tableView侧滑显示多个按钮(IOS 8.0)

近来公司项目由自己搭框架,决定不兼容IOS 7.0了。

则整理了8.0后的新特性,首先换上我们常用的tableView侧滑显示多个按钮功能。 由于8.0前要实现起来要自已写,而8.0后苹果为这一操作新增了方法。

这边不准备兼容7.0,用系统自带的侧滑功能就能显示多个按钮。 

上代码以防"老人痴呆":

效果:

代码,只要tableView实现几个方法即可,方便了很多:


#pragma mark 表格视图支持删除,显示多个按钮( iOS8后的新属性 )
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // add a button to delete
    __weak MyDeviceVC *weakSelf = self;
    UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
    {
        NSLog(@"删除");
        [weakSelf showDeleteConfimIndexPath:indexPath];
        
//        [_arrData removeObjectAtIndex:indexPath.row];
//        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
        
    }];

    // add a buutoon to reName DeviceName
    UITableViewRowAction *reNameAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"重命名" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
    {
        NSLog(@"重命名");
        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
        
    }];
//    reNameAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    reNameAction.backgroundColor = [UIColor lightGrayColor];
    // return the array for showButtons ...
    return @[deleteRowAction,reNameAction];
    
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值