tableView的系统删除和点击删除

在项目中删除cell这个功能用到的地方很多,下面是系统删除和点击删除两种

1.系统协议方法删除:

返回删除协议方法

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewCellEditingStyleDelete;

}



遵守协议方法

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [_numberArray removeObjectAtIndex:indexPath.section];

        [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];

}

   [self.tableView reloadData]; 

}


2.自定义button删除

首先设置button的tag值为index path.section


然后在button的点击方法里面实现

 NSIndexPath *index = [NSIndexPath indexPathWithIndex:sender.tag];

    [self tableView:self.tableViewcommitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:index];

    [self.tableView reloadData];



这里需要说明一下,上面方法是删除section的方法,如果是row的话只需改成row,[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.sectionwithRowAnimation:UITableViewRowAnimationAutomatic];  这个方法要换成删除index的方法.记得要加刷新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值