XcoderX
XcoderX

Reputation: 23

Problem with savin data!

I have a UitableView and its a checklist. I want to be able to save data when the user leaves the view. Then when the view is opened back up i want there to be the saved data. When i say saved data i mean that the table view is able to add and delete cells also i want to be able to save the checkmarks. Could somebody please provide me with a way or an idea on how to do this?

i know i can save data with:

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

and then save the data to defaults, but i need know how on saving the table view's cells that are add and or deleted! also i would like to know how to save the checkmarks!

Thank you, Kurt

Upvotes: 0

Views: 60

Answers (2)

Alex Nichol
Alex Nichol

Reputation: 7510

I would suggest using either Core Data, or NSCoding. NSCoding allows you to encode an object as NSData, and reload a replica of that object from NSData.

For instance, saving and loading an array of strings through NSCoding would be something like this:

NSArray * array = [NSArray arrayWithObjects:@"This", @"Is", @"A", @"Test"];
NSData * encoded = [NSKeyedArchiver archivedDataWithRootObject:array];
// save the encoded data to a file...
// load the encoded data from a file...
NSArray * decodedArray = [NSKeyedUnarchiver unarchiveObjectWithData:encoded];

Of course, you will need to implement some NSCoding stuff yourself if you plan on using classes more complicated than NSDictionary, NSArray, NSString, etc.

Documentation for NSKeyedArchiver can be found here. You can also find documentation for the NSCoding protocol here.

Upvotes: 0

Related Questions