当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS 用editActionsForRowAtIndexPath:删除cell时候回出现崩溃

iOS 用editActionsForRowAtIndexPath:删除cell时候回出现崩溃

2018年04月19日  | 移动技术网移动技术  | 我要评论

先上代码

// 删除cell操作

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

__weak typeof(self)weakSelf = self;

UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

[weakSelf.dataSource removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}];

return @[delete];

}

报错如下:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.52.10/UITableView.m:2012

哈哈哈哈哈哈,,,忍不住笑自己逗比了,哈哈哈哈

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return _dataSource.count; // 刚刚这里调试之前写死的数据,哈哈哈哈

}

 

再不行,看到网上有人添加了两句

 

// 删除cell操作

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

 

__weak typeof(self)weakSelf = self;

UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

[weakSelf.dataSource removeObjectAtIndex:indexPath.row];

[tableView beginUpdates]; // 开始刷新

[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

[tableView endUpdates]; // 结束刷新

}];

return @[delete];

}

但是本人亲测,要不要这两句都一样可以正常运行,等下再看看是否会有其他影响。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网