delete row UITableView index issue

前端 未结 11 1761
遥遥无期
遥遥无期 2021-02-13 04:24

I\'m using the code below to delete a row in my tableview. First I delete the object from my array and then from the tableview using this code:

let i = IndexPath         


        
11条回答
  •  我寻月下人不归
    2021-02-13 04:35

    Try this!

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
    
            //1. remove data from model
            data.remove(at: indexPath.row)
    
            //2. remove row from view
            tableView.deleteRows(at: [indexPath as IndexPath], with: .fade)
        }
    }
    

提交回复
热议问题