删除持久存储以删除实体的所有条目的正确时间
我正在使用包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要删除持久存储,您需要关闭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.