从子上下文更新关系时,NSFetchedResultsController不刷新 [英] `NSFetchedResultsController` not refreshing when updating relationship from child context

查看:80
本文介绍了从子上下文更新关系时,NSFetchedResultsController不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在子上下文上对托管对象进行更改,然后保存该上下文,如果更改仅是针对该对象的关系,则不会刷新。除了更新上述对象的属性之外,还有解决方案吗?

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?

推荐答案

您是否尝试过调用合并更改后是否在上下文中添加-processPendingChanges ?苹果的文档指出

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


直到控制器的托管对象上下文收到processPendingChanges消息后,更改才会反映出来。

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

显然,这是在MacOS应用程序的事件循环结束时调用的,但尚不清楚或何时在iOS上调用它。

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.

此外,请确保已在NSFetchedResultsControllerDelegate中实现了至少一种更改跟踪方法,否则,您将不会跟踪上下文的任何更改。再次来自Apple:

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:


委托必须实现至少一种更改跟踪委托方法,才能启用更改跟踪。提供一个空的controllerDidChangeContent:实现就足够了。

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.

这篇关于从子上下文更新关系时,NSFetchedResultsController不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆