有谁知道退出视图时如何保存数据?
我有一个 UITableView 及其清单。我可以向表格添加新单元格,您也可以删除它们。我想知道当有人离开/退出视图时如何保存表数据!这可能吗?谢谢大家:D
我正在用它来保存数据:: 这可行吗?
NSArray *sourceData = [[NSUserDefaults standardUserDefaults] arrayForKey:@"funds"];
if (!sourceData)
{
NSString * myFile = [[NSBundle mainBundle]pathForResource:@"cells" ofType:@"plist"];
sourceData = [[NSMutableArray alloc]initWithContentsOfFile:myFile];
}
self.cells = [NSMutableArray array];
for (NSDictionary *immutableCellDictionary in sourceData)
{
[self.cells addObject:[NSMutableDictionary
dictionaryWithDictionary:immutableCellDictionary]];
}
I have a UITableView and its a checklist. I can add new cells to the table and you can also delete them. I want to know how to save the tables data when someone leaves/exits a view! Is this possible?Thanks everyone: D
I am using this to save the data:: would this work?
NSArray *sourceData = [[NSUserDefaults standardUserDefaults] arrayForKey:@"funds"];
if (!sourceData)
{
NSString * myFile = [[NSBundle mainBundle]pathForResource:@"cells" ofType:@"plist"];
sourceData = [[NSMutableArray alloc]initWithContentsOfFile:myFile];
}
self.cells = [NSMutableArray array];
for (NSDictionary *immutableCellDictionary in sourceData)
{
[self.cells addObject:[NSMutableDictionary
dictionaryWithDictionary:immutableCellDictionary]];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全取决于您所说的退出/离开视图的含义。一种选择是使用
viewWillDisappear:
如果这对您的应用程序来说不合适,请提供有关您想要何时保存视图数据的更多详细信息。
It all depends on what you mean by exiting/leaving a view. One option is using
viewWillDisappear:
If this is not fine with your app, please give some more detail about when exactly you want to save the view data.