2016-08-03 93 views
0

强调textreason:滑动删除的UITableView细胞

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) 
and plus or minus the number of rows moved into or out of that 
section (0 moved in, 0 moved out). 

***第一掷调用堆栈

我,当我试图删除

回答

0

你的问题还不清楚,按照这个错误这些步骤

  1. 在委托方法commitEditingStyle中,从数组中删除对象。
  2. 然后在更新后的数组上应用deleterow动画。

我认为üR值不要从您的收藏即阵列

1

删除对象时,此错误意味着,当你更新删除后的UITableView,您正在使用的数据源尚未更新的阵列。

换句话说:

你有NSArray的dataArray你是在你的UITableViewDelegate使用cellForRowAtIndexPath。 您动画单元删除的行,但你永远不会调用

[dataArray removeObjectAtIndex:index];

所以当表再次呈现,在预计的UITableView那里是5个项目,但你的阵列仍然有6

0

试试这个代码。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [tableDataArray removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     [self.tableView reloadData]; 
} 
} 


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 

} 

对于更多的参考,您可以访问here