delete row UITableView index issue

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

    I was having this problem but none of the previous answers worked for me. If you run myTableView.reloadData() within the same block as myTableView.deleteRows(at:with:), the animation doesn't run correctly.

    You can run myTableView.performBatchUpdates(updates:completion:) where you delete your row in the updates handler and reload your data in the completion handler. This way, the deletion animation runs properly and the index rows sync up.

    myTableView.performBatchUpdates({
        myTableView.deleteRows(at: [i], with: UITableViewRowAnimation.left)
    }, completion: {finished in
        myTableView.reloadData()
    })
    

提交回复
热议问题