iphone - tableView:commitEditingStyle:forRowAtIndexPath:导致断言失败

标签 iphone ios uitableview

我有一个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/

相关文章:

iphone - 打开页面时出现问题(许可协议(protocol)页面)

iPhone应用程序将对象数组作为无法识别的参数传递给.net SOAP Web服务

iphone - 单元格处于编辑模式时如何显示披露指示符?

iphone - iPhone中的异常抛出JSON支持程序

iphone - UITableView 上冲突的手势识别器

iphone - iPhone OS 3.0.1 会毁掉你的开发手机吗?

ios - block 动画立即完成,但 CABasicAnimation 可以与自定义动画属性一起正常工作

ios - 在 UIView 外部添加边框(而不是在内部)

ios - 由于“NSInvalidArgumentException”而终止应用程序

xcode - 将弹出框选择到静态单元格UITableView会导致编译错误