Reputation: 35
I want to save data to a specific index in my table.
Here's what I want to achieve theoretically:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cell.label.text forKey:indexPath];
What is the correct way of doing this?
Upvotes: 0
Views: 235
Reputation: 5369
You can modify code as below
NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
[userdefaults setObject:cell.label.text forKey:[NSString stringWithFormat:@"$$%d",indexPath.row]]; // modify as per your requirement
[userdefaults synchronize];
For Retrieving you can as below.
NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
cell.textLabel.text=[userdefaults valueForKey:[NSString stringWithFormat:@"$$%d",indexPath.row]]; //modify as per your requirement
Hope it helps you...!
Upvotes: 0
Reputation: 5149
You can save the all the data that is relevant to the tableview in an array and store this array in standard user defaults.
EDIT
You CAN use NSUserDefaults for storing other objects than it originially supports. Follow this question here: How to save custom objects in array and store it in NSUserDefaults - iPhone
Upvotes: 0
Reputation: 10434
Try this
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cell.label.text forKey:[indexPath description]];
Upvotes: 1