不在获取请求中包含临时对象
我有一个处理表视图的获取结果控制器,并且我遇到一个问题,它还显示已在上下文中创建但未保存到存储中的新托管对象。我只想列出已保存的对象。
我尝试在获取请求中将 setInincludesPendingChanges 设置为 NO,但它不起作用!
任何建议将不胜感激!
谢谢,
迈克
I've got a fetched results controller handling a table view, and I'm having a problem that it is also showing new managed objects that have been created in the context but not saved to the store. I only want to list objects that have been saved.
I have tried setting the setIncludesPendingChanges to NO in the fetch request but it's not working!
Any advice would be greatly appreciated!
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过实现托管对象上下文堆栈解决了这个问题。当创建新记录时,我在另一个上下文中执行此操作,并将其推送到堆栈上,并且仅当用户保存更改时才合并更改。
I've overcome this issue by implementing a stack of managed object contexts. And when creating new records I do it in another context that I push onto the stack, and I only merge the changes if the user saves the changes.
setInincludesPendingChanges 似乎对我有用(至少在 3.0 模式下使用 SDK 3.1 的 Sim 中)。
setIncludesPendingChanges appears to be working for me (at least in the Sim using SDK 3.1 in 3.0 mode).
CoreDataBook 示例项目展示了一种创建用于编辑(或创建新模型对象)的“草稿本”上下文的方法,然后,一旦将更改保存到草稿,如何将其合并到主或应用程序上下文。
使用暂存可防止在其中创建的任何临时对象显示在主上下文中(直到您在保存时合并上下文)。
The CoreDataBook example project shows a way to create a "scratch pad" context for editing (or creating a new model object) and then, once you save changes to the scratch, how to merge it up to the main or application context.
Using the scratch prevents any temporary objects created in it from showing up in the main context (until you merge the contexts at save-time).