2

Hey guys i have a tableView and when the view is closed or left from, the tableViews data is saved! Could someone please provide some source code?? ANy help would be greatly appreciated!! Thanks :D -Kurt

XcoderX
  • 23
  • 7

1 Answers1

3

First get the data from the tableview cell and save that to saveString..

    NSString *saveString;   

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];  
    [prefs setObject:saveString forKey:@"keyToLookupString"];//saving an nsstring 
    NSString *myString = [prefs stringForKey:@"keyToLookupString"];//retrieving the string   

Source
EDIT :1
To save the data from the array to the NSString:

NSString *saveString=[yourArray objectAtindex:0];  

then save the saveString in the NSUerdefaults.
EDIT :2
There are two options for you to store the array in the NSUserDefaults.
First one:
If you are having 10 elements in the array means Create 10 NSString and store in that strings.
Second one:
store the array in the nsuserdefaults

Community
  • 1
  • 1
Aravindhan
  • 15,608
  • 10
  • 56
  • 71
  • hmm doesnt this only save the nsstring?? Is there a way i can save a tableView's text?? like its cell's text? – XcoderX Jul 20 '11 at 17:44
  • How you are adding the text in the tableview? – Aravindhan Jul 20 '11 at 17:45
  • i have a plist called "cells.plist" and im storing that data into an NSMutableArray called "cellText" – XcoderX Jul 20 '11 at 17:46
  • do you want to save the text from the array to nsuserdefaults ? – Aravindhan Jul 20 '11 at 17:49
  • yep exactly. in the app i can add cells to the tableView and i want to be able to save those too so when the user opens the app back up everything will be there! – XcoderX Jul 20 '11 at 17:50
  • okay, now do i have to do this for each index in the array? or is there a way to save each object in the array to this 1 string? And thanks a lot for the help :D – XcoderX Jul 20 '11 at 17:56