UITableView实现Cell的滑动删除

转载请标明出处:http://blog.csdn.net/android_ls/article/details/46680557 

UITableViewCell的滑动删除实现代码如下:

#pragma mark 当用户手指在Cell上滑动时会调用此函数
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section){
        // 返回UITableViewCellEditingStyleDelete时,Cell会做出响应显示Delete按键,
        // 点击Delete后会调用函数:
        // - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath)
        // 并把UITableViewCellEditingStyleDelete当做参数传递过去
        return  UITableViewCellEditingStyleDelete;
    } else {
        // 返回UITableViewCellEditingStyleNone时,Cell上不会出现Delete按键,即Cell不做任何响应。
        return  UITableViewCellEditingStyleNone;
    }
}

#pragma mark 对选中的Cell根据editingStyle进行操作
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        MyLog(@"我要删除这篇帖子,请执行命令,谢谢");
        
        
    }
}

已实现的效果图如下:

     



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值