ios - 重置上下文不会触发 fetchResultedController

标签 ios core-data nsfetchedresultscontroller nsmanagedobjectcontext

我将一个 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).

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

正如文档所说,如果上下文被重置或上下文被释放,则不会调用任何单独的通知或委托(delegate)方法。因此,您需要自己调用 performFetch 并重新加载接口(interface)。

关于ios - 重置上下文不会触发 fetchResultedController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30330005/

相关文章:

objective-c - iOS 上的数据源

ios - 使用 NSFetchedResultsController 移动行的方法及其委托(delegate)不起作用

iphone - 尝试调试错误: *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]

ios - 同一实体的核心数据多个实例 - 共享属性的实体

iphone - 核心数据并发 - NSManagedObjectContext

iphone - 我如何使用 NSFetchedResultsController 来获取基于实体关系的结果?

iphone - 如何在选择 tableView 行时更新我的​​ fetchedResultsController?

android - 我想在切换屏幕时保持秒表屏幕运行

ios - 处理通知权限警报按钮点击

ios - MPMoviePlayerViewController观看后隐藏StatusBar并销毁Frame