我们有 UITableViewController,它的 DataSource 是一个 NSFetchedResultsController。单击 UITableView 中的对象后,您将被定向到 UIViewController,您可以在其中设置一个标志 (YES/NO),这可能会导致从 NSFetchedResultsController (NSPredicate) 中删除:
- 带有标志的对象:YES 显示在 UITableView
- 带有标志的对象:NO 未在 UITableView 中显示
我们更新对象如下:
objectEntity updatedObject = self.oldobject;
[updatedObject setFlag: [NSNumber numberWithBool: NO]];
NSError *error;
[self.managedObjectContext save:&error];
保存更新会导致以下错误:
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0] with user Info (null)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException'. reason: '*** -[_NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
有任何想法吗?
更新:
异常发生在 NSFetchedResultsController 委托方法中
controller()didChangObject()atIndexPath... case: NSFetchedResultsChangeDelete tableView
deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
*** First throw call stack:
(0x334af2a3 0x3b1cc97f 0x333f934d 0x33407559 0x5e5e5 0x33326fe7 0x33400037 0x33d16599 0x332b4717 0x332b3c77 0x33235bf9 0x332a84cf 0x6174d 0x35478e1b 0x353a20c5 0x353a2077 0x353a2055 0x353a190b 0x353a1e01 0x352ca5f1 0x352b7801 0x352b711b 0x36fcd5a3 0x36fcd1d3 0x33484173 0x33484117 0x33482f99 0x333f5ebd 0x333f5d49 0x36fcc2eb 0x3530b301 0x20abd 0x3b603b20)
libc++abi.dylib: terminate called throwing an exception