Reputation:
Updated method:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
initialData[indexPath.section].remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else {
}
}
Error:
reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), 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).
How can I fix this?
Upvotes: 0
Views: 142
Reputation: 518
Read what your console is telling you very carefully.
Your data source is complaining that after you removed a row with removeAtIndexPaths()
it doesn't have the expected number of rows.
Make sure you maintain integrity in what you delete/ add and the data source changing accordingly as well. Also, make sure to make these changes on the main queue.
Good luck! :)
Upvotes: 1