delete row UITableView index issue

前端 未结 11 1728
遥遥无期
遥遥无期 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:27

    I use the following code in my applications:

    public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath){
    
        if editingStyle == UITableViewCellEditingStyle.delete
        {
            myArray.remove(at: indexPath.row)
            myArray2.remove(at: indexPath.row)
            // you would also save the new array here so that the next time you open the tableview viewController it shows the changes made.
    
            mytableview.reloadData()
    
        }
    }
    

提交回复
热议问题