我有一个分区的UITableView,它使用字典来调整教程中的代码(目前我没有链接,但是如果你真的需要的话,我可以找到它)。
无论如何,当我收到这个错误时,我正试图让它从列表中删除一个项目(警告:它很长)
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 (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).
我有点了解行数的信息,但我不知道如何解决这个问题。
如果要查看调试器信息,我将其粘贴在一起,因为它太长:
http://pastebin.com/0difSEnM
以下是我的代码:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)index {
NSDictionary *dictionary = [data objectAtIndex:index.section];
NSMutableArray *array = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"My Wishlists"]];
NSString *selectedWishlist = [array objectAtIndex:index.row];
//now remove the item
[array removeObjectAtIndex:index.row];
[data removeObjectAtIndex:index.section];
NSDictionary *newdictionary = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:array] forKey:@"My Wishlists"];
[data insertObject:newdictionary atIndex:0];
// [data addObject:newdictionary];
[mainTableView reloadData]; // tried without and with this, no difference
[mainTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationTop];
}
谢谢!
克里斯汀·斯图尔特