保存数据的问题!
我有一个 UitableView 及其清单。我希望能够在用户离开视图时保存数据。然后,当视图重新打开时,我希望有保存的数据。当我说保存的数据时,我的意思是表视图能够添加和删除单元格,我也希望能够保存复选标记。有人可以为我提供一种方法或想法吗?
我知道我可以使用以下方式保存数据:
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
然后将数据保存为默认值,但我需要知道如何保存添加和/或删除的表视图的单元格!我也想知道如何保存复选标记!
谢谢你, 库尔特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来核心数据在这里会很好
http://developer.apple.com/library/ ios/#documentation/DataManagement/Devpedia-CoreData/coreDataOverview.html
Sounds like core data would be good here
http://developer.apple.com/library/ios/#documentation/DataManagement/Devpedia-CoreData/coreDataOverview.html
我建议使用 Core Data 或 NSCoding。 NSCoding 允许您将对象编码为 NSData,并从 NSData 重新加载该对象的副本。
例如,通过 NSCoding 保存和加载字符串数组将是这样的:
当然,如果您打算使用比 NSDictionary、NSArray、NSString 等更复杂的类,您将需要自己实现一些 NSCoding 的东西。
NSKeyedArchiver 的文档可以找到此处。您还可以找到 NSCoding 协议的文档 这里。
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:
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.