当我尝试从表中删除一行时,发生了一个非常奇怪的错误。我得到的错误是:
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) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
我读过在调用deleteRowsAtIndexPaths之前有人没有从数据源中删除对象时,这通常是一个错误。但是,我这样做......这是我的代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
/* Remove from DB */
[dbHandler deleteRow:indexPath];
/* Removing row from data source */
[[self.listData objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
/* Remove row from table - It fails on this line... */
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationTop];
}
}
当我在调试器中逐步执行此操作时,它肯定会从数据源中删除该对象。我还需要做些什么吗?
答案 0 :(得分:0)
我想通了......当我要加载的行多于已经在屏幕上呈现的行时,我正在向我的表添加一行。类似于Mail应用程序执行“加载更多”功能的方式...当我删除它时,我没有考虑这个额外的单元格。