左划删除

-(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的个数不一致。

 

posted @ 2016-04-17 11:31  羊羊羊🐑  Views(160)  Comments(0Edit  收藏  举报