使用 CoreData 自动持久从 NSArrayController 中删除对象
我有一个 NSTableView,其中一列绑定到 NSArrayController,表示来自 NSManagedObjectContext 的实体集合。我还有一个“删除”按钮,连接到 NSArrayController 的删除操作,一切正常 - 表格显示数据,当我单击“删除”时,实体将从表格中删除等。
然而,这种删除似乎只发生在对象图中,从未持久化到磁盘。是否有任何标志或方法可以自动将此类更改持久保存到对象图,或者是为删除按钮引入新的 IBAction 并在控制器上显式调用第一个 remove
的唯一方法,并且然后在 NSManagedObjectContext
上保存
?
I have a NSTableView
with one column bound to NSArrayController
representing a collection of entities from a NSManagedObjectContext
. I also have a "remove" button that is connected to NSArrayController's
remove action, and it all works fine - table is showing data, when I click 'remove', the entity gets removed from the table etc.
However, this removal seems to be only happening in the object graph is never persisted to disk. Is there any flag or a way to persist such changes to object graph automatically or is the only way introducing new IBAction
for the remove button and explicitely calling first remove
on the controller and then save
on NSManagedObjectContext
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎在谈论两个不同的问题:
如果您的内容数组绑定到其他源,您可以检查内容数组绑定的“删除时删除对象”选项。如果内容仅仅是您提供的实体的所有实例(即,未建立内容/数组绑定,并且只是获取所有 Foo 实例),我希望该对象被标记为删除。将更改保存到存储中最终会删除对象。
要立即保存更改,您可能需要自己的单独操作来传递“删除此对象并保存”操作。在这种情况下,您可以执行删除/删除,要求托管对象上下文处理PendingChanges,然后调用保存例程。
You appear to be talking about two separate issues:
If your content array is bound to some other source, you can check the "Deletes objects on remove" option for the content array binding. I would expect the object be marked for deletion if the contents is merely all instances of your supplied entity (ie, the content / array binding is not established and it's just fetching all Foo instances). Saving the changes to the store ultimately deletes the objects.
To save changes immediately, you'd probably need your own separate action through which to pass your "delete this object and save" action. In that case, you can perform your remove/delete, ask the managed object context to processPendingChanges, then call the save routine.