Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

swift4 - スワイプでtableviewのセル削除

More than 1 year has passed since last update.

実装

ViewController.swift
    //セルの編集許可
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
    {
        return true
    }

    //スワイプしたセルを削除 ※arrayNameは変数名に変更してください
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == UITableViewCell.EditingStyle.delete {
            arrayName.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath as IndexPath], with: UITableView.RowAnimation.automatic)
        }
    }

 参考

https://qiita.com/Ryosuke-Hujisawa/items/cf00b02efc96b4330369

Lulu34
swiftを勉強していた元Webディレクター。今は動画編集に夢中💛 2018.5 初アプリリリース。アップルにお金払うのやめたので消えましたが、記録はqiitaに残っています。
https://youtube.com/channel/UCz573BArC6nNmzELk9HeEfw
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away