先上代码
// 删除cell操作
- (NSArray
__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
__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];
}
但是本人亲测,要不要这两句都一样可以正常运行,等下再看看是否会有其他影响。
如对本文有疑问, 点击进行留言回复!!
Codeforces Round #657 (Div. 2) C题
hdu2222 Keywords Search(ac自动机模板-kuangbin)
IOS开发控件视图day08:监听文本框状态设置按钮状态不可点击且变灰
网友评论