【发布时间】:2016-05-04 07:33:42
【问题描述】:
NSFetchedResultsController 在 -controllerDidChangeContent: 插入新记录并保存到persistentStore 时崩溃。
代码:
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
NSLog(@"== UPDATING indexPath (%@) newIndexPath (%@) type %i", indexPath, newIndexPath, (int)type);
switch (type) {
case NSFetchedResultsChangeDelete: {
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
break;
}
case NSFetchedResultsChangeInsert: {
[self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
break;
}
case NSFetchedResultsChangeMove: {
[self.tableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
break;
}
case NSFetchedResultsChangeUpdate: {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
break;
}
default:
break;
}
}
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"== BEGIN UPDATING");
[self.tableView beginUpdates];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"== END UPDATING");
[self.tableView endUpdates];
}
注意:- 在目标应用程序中,FetchedResults 委托是在 UITableViewController 子类中实现的。 FetchedResultsController 正在处理子托管对象上下文。
【问题讨论】:
-
您是否收到任何错误日志?如果是,请在此处粘贴。
标签: ios objective-c ipad core-data ios8.3