我将一个 fetchResultedController
绑定(bind)到一个上下文,即 reset
-ed。
在此之前,我已将记录添加到此上下文中,并且使用 .Insert
changeType
调用了 didChangeObject
,但在 之后reset
我原以为 didChangeObject
会被 .Delete
changeType
调用,但它并没有发生。
知道如何触发接收带有 .Delete
参数的调用吗?
最佳答案
如果您查看 NSFetchedResultsController 文档,有一节是关于“处理对象失效”的,其中说明如下,
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).
正如文档所说,如果上下文被重置或上下文被释放,则不会调用任何单独的通知或委托(delegate)方法。因此,您需要自己调用 performFetch 并重新加载接口(interface)。
关于ios - 重置上下文不会触发 fetchResultedController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30330005/