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
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()
})