错误是:
* Assertion failure in -[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit/UIKit-2903.23/UITableView.m:1330
* 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 (1) 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,1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,0 moved out).’
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView beginUpdates]; SequenceData *sd = [self.fetchedResultsController objectAtIndexPath:indexPath]; [self.managedObjectContext deleteObject:sd]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; }
我的NSFetchedResultsController的设置就像Ray Wanderlich的教程(http://www.raywenderlich.com/999/core-data-tutorial-for-ios-how-to-use-nsfetchedresultscontroller)
行数由以下因素确定:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id sectionObjects = [[self.fetchedResultsController sections] objectAtIndex:section]; NSInteger nbObjects = [sectionObjects numberOfObjects]; return nbObjects; }
看起来fetch没有更新(行数不变).我是否需要取自己(这不是由fetch控制器处理)?
显然,我在这里缺少一些基本的东西.不要犹豫,建议基本的答案.
我首先用控制器实现了这个:didChangeObject:…方法.错误是一样的,但有些细节不同.
编辑
我相信我的问题是固定的.两个答案(来自CX和Martin)帮助我找到了答案.马丁得到了答案,因为解释有助于我更好地理解……