删除持久存储以删除实体的所有条目的正确时间

发布于 2024-09-28 10:37:53 字数 243 浏览 1 评论 0原文

我正在使用包含 UITableView 和 UISearchTableView 的 UITableViewController。 该表列出了例如 1000 个条目。我想为用户提供一个删除所有按钮 特定实体的条目。因为循环所有托管对象并保存上下文需要很长时间,所以我想到通过删除持久存储并重建堆栈来删除。

现在我的问题是:如何在 UITableViewController 中执行此操作?我不想重新启动应用程序以进行删除,因此我想从应用程序委托中移动代码。

I am using an UITableViewController containing a UITableView and an UISearchTableView.
The table lists e.g. 1000 entries. I want to provide the user a button to delete all
entries of a specific entity. Because looping over all managed objects and saving the context takes a very long time, I thought of deleting by removing the persistent store and rebuilding the stack.

Now to my questions: How can I do this in the UITableViewController? I don't want to restart the app for deletion so I want to move the code from the app delegate.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

笑脸一如从前 2024-10-05 10:37:53

要删除持久存储,您需要关闭Core Data堆栈,删除持久存储,然后重建堆栈。

我只需使用 tableview 的 beginUpdate 方法来冻结表,然后清空 fetchedResults 控制器,然后清空核心数据堆栈。删除持久存储,然后重建堆栈并创建一个新的获取结果控制器。然后告诉‘endUpdate’然后告诉表重新加载数据。这一切都需要用户察觉不到的短暂时间。

To delete the persistent store, you need to close down the Core Data stack, delete the persistent store and then rebuild it the stack.

I would just use the tableview's beginUpdate method to freeze the table, then nil out the fetchedResults controller, then the Core Data stack. Delete the persistent store then rebuild the stack and create a new fetched results controller. Then tell the `endUpdate' and then tell the table to reload data. That should all take brief time unnoticeable by the user.

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