开发者

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 t开发者_如何学Chen 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


Sounds like core data would be good here http://developer.apple.com/library/ios/#documentation/DataManagement/Devpedia-CoreData/coreDataOverview.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜