NSFetchedResuktsController - 缓存导致崩溃?

时间:2014-11-26 21:58:14

标签: ios core-data nsfetchedresultscontroller

我有一个NSFetchedResultsController,其静态请求永远不会改变。如果先前的记录数为0(上次使用fetchedResultscontroller),然后在其他地方(当用户在另一个viewController上时),新记录将添加到核心数据中,这些数据将成为请求的一部分,下次加载时我遇到了崩溃的页面。

只有从fetchedResultsController检索到的前一个记录数为0时才会发生此崩溃。

CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array with userInfo (null)
2014-11-26 13:55:50.772 Company[47714:613] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'


_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest
                                                                    managedObjectContext:context
                                                                      sectionNameKeyPath:self.sectionNameKeyPath
                                                                               cacheName:self.fetchedResultsControllerCacheName];

对此有任何解决方案吗?

1 个答案:

答案 0 :(得分:0)

您是否有多个使用相同缓存名称的NSFetchedResultsControllers?我似乎记得那给我带来了一些麻烦。它也在documentation

中推荐

"如果您有多个具有不同配置的读取结果控制器(不同的排序描述符等),则必须为每个控制器指定不同的缓存名称。"

相关问题