贡献作者 -【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] }