删除CoreData对象,然后调用会导致SIGABRT

我支持删除包含tableView的UIView中的行:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.fetchedResultsController.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; NSError *error; if (![[self.fetchedResultsController managedObjectContext] save:&error]) { NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo], [error localizedDescription]); } else {NSLog(@"Apparently successful");} [self.tableView reloadData]; } } 

当我尝试这个时,我在控制台中获得“显然成功”的消息,然后在configureCell中获得SIGABRT。 就好像某个地方没有删除对象,而configureCell正试图呈现一个丢失的对象。 (当我重新运行应用程序时,记录已经消失。)

有什么想法吗?

使用NSFetchedResultsController时,不应该有[self.tableView reloadData]

删除对象时,将为您调用正确的NSFetchedResultsControllerDelegate方法,您应该在此处更新表视图。

创建一个空的基于导航的应用程序,并选中“ 使用核心数据存储”复选框。 你会得到一个空的项目,所有这一切都是正确的。 这将是一个很好的例子。