2

当我不手动时synthesizeNSFetchedResultsController property我的应用程序崩溃了。

崩溃日志:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070
2013-03-06 15:09:15.667 Staff Manager[6673:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '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 (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 2 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

当我synthesize按照预期进行所有工作时:

@synthesize fetchedResultsController = _fetchedResultsController;

你可以解释吗?

我的知识状态是 Xcode 的编译器为我做这件事。

Xcode 版本:4.6 部署目标:6.1

应用程序在此方法中崩溃(最后一行)

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

        [self.managedObjectContext deleteObject:personToDelete];
        [self.managedObjectContext save:nil];

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self performFetch];

        [self.tableView endUpdates];
    }
}
4

1 回答 1

1

我只能说,当您使用已经创建的nsfetchresultscontroller从xcode创建项目时,fetchresultscontrollerdelegate的创建方式是在您删除显示的托管对象时已经执行deleteRowsAtIndexPaths,它会自动删除相应的tableview单元格

你应该只保留 deleteObject 部分

Person *personToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];

[self.managedObjectContext deleteObject:personToDelete];
[self.managedObjectContext save:nil];
于 2013-03-06T14:58:55.477 回答