まだどこにもないアプリを作る

アプリ開発でつまづいたところなどを中心に記事にして行きます。

(Swift5) tableViewのスワイプして削除を無効にする

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {

        folderNameArray.remove(at: indexPath.row)

        tableView.deleteRows(at: [indexPath], with: UITableView.RowAnimation.automatic)

    }

 

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {

        if tableView.isEditing == true{

            return .delete

        }else{

            return .none

        }

    }

これでtableViewがisEditingの時でなおかつ

赤い削除マークを押した時だけ削除ができるようになります。