如图下所示
自定义一个视图,放在cell的右边边缘外,覆盖左滑删除的删除按钮
image.png
其它就是补充一些系统UITableView左滑删除的代码
// MARK: 左滑删除
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
// 不设置这个,可以避免左滑偶尔出现红底的bug
// func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
// return "删除"
// }
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if indexPath.row < self.dataList.count {
let model = self.dataList[indexPath.row]
let alert = UIAlertController(title: "确定要删除?", message: "", preferredStyle: .alert)
let saveAction = UIAlertAction(title: "删除", style: .default) { (action :UIAlertAction!) in
}
let cancelAction = UIAlertAction(title: "取消", style: .cancel) { (action: UIAlertAction) in
}
saveAction.setValue(UIColor.red, forKey: "_titleTextColor")
alert.addAction(saveAction)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
}
}
网友评论