【swift3.0】【tableView 侧滑删除展示】

贡献作者 -【XJDomain】
博客XJ:  https://my.oschina.net/shengbingli/blog
GitHub直播地址https://github.com/lishengbing/XJDomainLive

1:展示一个系统自定的删除按钮方式_1

 override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        if indexPath.section == 0 {
            return .none
        }
        return UITableViewCellEditingStyle.delete
    }

 

 

1.1:展示一个系统自定的删除按钮方式_2

 override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        if indexPath.section == 0 {
            return false
        }
        return true
    }

 

 

2.修改展示的字样

override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }

 

 

3:删除的点击事件获取

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            print("删除事件.....")
        }
    }

 

 

4:展示tableview cell侧滑多个按钮显示的方式:一个方法搞定!!!

 override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let item1 = UITableViewRowAction(style: .normal, title: "item1") { (action, indexPath) in
            print("item1-----")
        }
        item1.backgroundColor = UIColor.green
        
        let item2 = UITableViewRowAction(style: .destructive, title: "item2") { (action, indexPath) in
            print("item2-----")
        }
        item2.backgroundColor = UIColor.blue
        
        let dele = UITableViewRowAction(style: .normal, title: "删除") { (action, indexPath) in
            print("dele-----",action)
            action.backgroundColor = UIColor.orange
            
        }
        dele.backgroundColor = UIColor.red
        //dele.backgroundEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
        
        
        return [dele, item1, item2]
    }

 

 

转载于:https://my.oschina.net/shengbingli/blog/811522

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值