重置上下文不会触发 fetchResultedController

reset context does not fire fetchResultedController

我将 fetchResultedController 绑定到上下文,即 reset-ed。

在此之前,我已将记录添加到此上下文中,并且 didChangeObject 是通过 .Insert changeType 调用的,但在 reset 之后,我期望 [=12] =] 会用 .Delete changeType 调用,但它并没有发生。

知道如何触发接收带有 .Delete 参数的呼叫吗?

如果您查看 NSFetchedResultsController 文档,有一段关于 "Handling Object Invalidation" 的内容如下,

When a managed object context notifies the fetched results controller that individual objects are invalidated, the controller treats these as deleted objects and sends the proper delegate calls.

It’s possible for all the objects in a managed object context to be invalidated simultaneously. (For example, as a result of calling reset, or if a store is removed from the the persistent store coordinator.) When this happens, NSFetchedResultsController does not invalidate all objects, nor does it send individual notifications for object deletions. Instead, you must call performFetch: to reset the state of the controller then reload the data in the table view (reloadData).

https://developer.apple.com/library/prerelease/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/index.html

正如文档所说,如果上下文被重置或上下文被释放,none 将调用单独的通知或委托方法。所以,你自己调用performFetch然后重新加载接口就是你的工作了。