`NSFetchedResultsController` not refreshing when updating relationship from child context

陌路散爱 提交于 2019-12-11 10:27:33

问题


If I make changes to a managed object on a child context and then save that context, if the changes are only to the relationships of that object, it does not refresh. Is there a solution to this besides also updating a property of said object?


回答1:


Have you tried calling -processPendingChanges on the context after you have merged the changes? Apple's documentation states

Changes are not reflected until after the controller’s managed object context has received a processPendingChanges message.

Apparently this gets called at the end of the event loop for MacOS applications, but it's not clear of or when it's called on iOS.

Also, ensure you've implemented at least one of the change-tracking methods in your NSFetchedResultsControllerDelegate, otherwise you won't be tracking any changes to the context. Again from Apple:

A delegate must implement at least one of the change tracking delegate methods in order for change tracking to be enabled. Providing an empty implementation of controllerDidChangeContent: is sufficient.



来源:https://stackoverflow.com/questions/31463935/nsfetchedresultscontroller-not-refreshing-when-updating-relationship-from-chil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!