0

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?

3 Answers3

1

Try this

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cell.label.text forKey:[indexPath description]];
Rajesh
  • 10,318
  • 16
  • 44
  • 64
  • 1
    `[indexPath description]` seems to be that thing I need. I will give you feedback as soon as I get everything working :D BTW How do I turn `[indexPath description]` back to an indexPath for loading? – Stack Asker Sep 01 '14 at 05:39
0

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

Community
  • 1
  • 1
avismara
  • 5,141
  • 2
  • 32
  • 56
0

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...!

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59