我有一个tableView显示一个对象的NSMutableArray
,并且我目前正在尝试实现tableView:commitEditingStyle:forRowAtIndexPath:
方法。如果我将[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
这一行注释掉,那么在更新UI之外,一切都可以正常工作。
这是我对方法的实现:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.modelClass removeObjectAtRow:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
这是我得到的错误:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2280.1/UITableView.m:1060
其他问题的答案表明我需要将
@[indexPath]
替换为[NSArray arrayWithObject:indexPath]
,而这又出现了相同的错误。
最佳答案
这是因为UITableView
在删除行之后再次输入了数据源方法numberOfRowsInSection
。确保它返回正确的行数,即self.modelClass.count
中的numberOfRowsInSection
。
关于iphone - tableView:commitEditingStyle:forRowAtIndexPath:导致断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11288011/