21
我使用Matt Gallagher的GenericTableViewController
想法来控制我的UITableViews
。我的数据源是NSFetchedResultsController
。我该如何制作deleteRowsAtIndexPaths:使用GenericTableViewController?
http://cocoawithlove.com/2008/12/heterogeneous-cells-in.html
一切工作正常,直到我尝试删除单元格。
我在我的视图控制器下面的代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object.
NSManagedObjectContext *context = [wineryController managedObjectContext];
[context deleteObject:[wineryController objectAtIndexPath:indexPath]];
NSError *error;
if (![context save:&error]) {
// Handle the error.
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
最后一行在控制台中的相当冗长的解释崩溃:
*** 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 (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
OK,我明白它在说什么。 ..行不会被删除(我会假设),因为我没有转发一些消息到正确的地方(因为我已经从它的'正常'位置移动了一些代码)...任何人都知道哪一个?我完全沉迷于这一个。
+1非常感谢您的回答。 – 2010-03-31 10:17:55