1

我正在使用ECSlidingViewController进行路径& FB样式的UI。两个UITableViews,其中一个(细节)显示为主视图,第二个(主人)显示为sidemenu。两者都由Core Data提供支持。核心数据在删除父表格时崩溃

我在删除sidemenu UITableView中的父表行时遇到了严重的崩溃,但仅当详细信息页面在删除时显示父行的子级时才会发生硬性崩溃。所有其他行按预期删除。

删除该行被处理:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 
    } 
} 

我得到的日志中出现以下错误:

CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

delete rule设置为抵消是否有帮助?

我猜核心数据一次从NSFetchedResultsController删除所有的孩子,然后UITableVIew得到所有困惑?

如何在没有崩溃的情况下删除父级和子级NSManagedObjects?

+0

删除对象后,执行新的读取和重新加载数据。你也可以使用NSFetchResultsControllerDelegate。希望能帮助到你。 – 2013-05-12 18:28:12

+0

我无法删除没有崩溃的对象。单个项目删除工作正常。我不明白为什么它试图一次删除所有的子项目。 – JMWhittaker 2013-05-12 19:29:35

回答

0

经过代码很多次,事实证明,我嵌套[self.tableView beginUpdates][self.tableView endUpdates]这是不同步的,我连续两次调用endUpdates。

我已经打了很多次现在开发这个程序。如果你有这样的崩溃检查,你可能使用CS193P课程的CoreDataTableViewController检查你使用beging和结束更新!