デモ
デフォルト
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
array.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}
ボタンの文字や背景色を変えたい場合
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteButton: UITableViewRowAction = UITableViewRowAction(style: .normal, title: "削除") { (action, index) -> Void in
self.array.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
deleteButton.backgroundColor = UIColor.red
return [deleteButton]
}
関連記事
・【iOS11】UITableViewセルのスワイプで削除を無効にする方法【Swift】