delete row UITableView index issue

前端 未结 11 1716
遥遥无期
遥遥无期 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-13 04:48

    Any methods that insert or delete rows must be called inbetween tableView.beginUpdates() and tableView.endUpdates() . So your code must be:

    let i = IndexPath(item: rowNum, section: 0)
    myArray.remove(at: rowNum)
    
    tableView.beginUpdates()
    
    myTableView.deleteRows(at: [i], with: UITableViewRowAnimation.left)
    
    tableView.endUpdates()
    

提交回复
热议问题