I am getting an error when trying to delete a row from a UITableView:
Here is the data for my Table View:
var tmpArray = ["test"];
Here is how the TableView gets the number of rows:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tmpArray.count;
}
Here is the body of the method I call to remove rows:
self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic);
tmpArray.remove(at: 0);
Here is the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
The odd part is that there should be 1 row in the section before the row is deleted, not 2.
Any ideas as to why this error is occurring?
I have reviewed several posts, and although relevant, the solution provided here does not work: UITableView Deleteing row error
Update When I call the remove commands separately, the error still persists:
tmpArray.remove(at: 0);
self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic);
Error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
tmpArray.remove(at:0)before you calldeleteRows.