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