有谁知道退出视图时如何保存数据?

发布于 2024-11-25 10:10:33 字数 613 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-12-02 10:10:33

这完全取决于您所说的退出/离开视图的含义。一种选择是使用 viewWillDisappear:

视图将消失:

通知视图控制器其视图即将被消除、覆盖或以其他方式从视图中隐藏。

子类可以重写此方法并使用它来提交编辑更改、放弃视图的第一响应者状态或执行其他相关任务。

如果这对您的应用程序来说不合适,请提供有关您想要何时保存视图数据的更多详细信息。

It all depends on what you mean by exiting/leaving a view. One option is using viewWillDisappear:

viewWillDisappear:

Notifies the view controller that its view is about to be dismissed, covered, or otherwise hidden from view.

Subclasses can override this method and use it to commit editing changes, resign the first responder status of the view, or perform other relevant tasks.

If this is not fine with your app, please give some more detail about when exactly you want to save the view data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文