方式一:
删除数据源中对应的数据,然后reloadData。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// 先删除数据源
[self.commonGoodsArray removeObjectAtIndex:indexPath.row];
// 再reloadDate
[self.tableView reloadData];
}
方式二:
先删除对应的数据源,再删除对应的cell。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// 先删除数据源
[self.commonGoodsArray removeObjectAtIndex:indexPath.row];
// 再删除cell
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
注:先删除cell会崩溃。
当使用方式一出现体验不友好的状况时,可以试试方式二。
网友评论