- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;删除报错问题

前几天做UItableView删除cell的时候报了这个错:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:1623

错误代码如下:

- (IBAction)deleteClick:(UIButton *)sender {
    
    NSArray *array =  _mTableView.indexPathsForSelectedRows;
    
    [_mTableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
    [self selectCancel:nil];

}

页面效果如下:

网上查了一下,说是没有移除数据源,所以修改了一下代码,将数据移除了,解决了这个问题

- (IBAction)deleteClick:(UIButton *)sender {
    
    NSArray *array =  _mTableView.indexPathsForSelectedRows;

    NSMutableIndexSet *set = [[NSIndexSet indexSet] mutableCopy];
    for (NSIndexPath *path in array) {
        [set addIndex:path.row];
    }
    
    [_woDeArray removeObjectsAtIndexes:set];
    
    [_mTableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
    [self selectCancel:nil];

}
原文地址:https://www.cnblogs.com/lilufeng/p/5141463.html