-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.dataArr removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

  需要注意的是,self.dataArr必须是可变类型,但是不能是懒加载的方式,因为,remove后,这个dataArr的个数还是没变,这样,删除会不成功,会报错。因为dataArr的个数和tableView里面的Row的个数不一致。

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2021-11-19
  • 2021-06-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-07-28
相关资源
相似解决方案