码迷,mamicode.com
首页 > 其他好文 > 详细

左划删除

时间:2016-04-17 13:00:13      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

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

 

左划删除

标签:

原文地址:http://www.cnblogs.com/tanglimei/p/5400610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!