I have worked with deleting and reloading rows at specified index paths but never inserting. Here is what I am trying to do:
func reloadTableView(newIndexPaths: [IndexPath]) {
print(dataSource.numberOfItems()) // prints 44
print(newIndexPaths.count) // prints 22
tableView.beginUpdates()
tableView.insertRows(at: newIndexPaths, with: .none)
tableView.endUpdates() // Crashes before this line
}
And here is the crash that I receive:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 2. The number of rows contained in an existing section after the update (44) must be equal to the number of rows contained in that section before the update (22), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
What doesn't make sense is that it tells me that only 1 item was trying to be inserted but in fact I am actually inserting 22. My data source is properly updated so why isn't this working?
newIndexPaths- are there 22 distinct indexpaths in there, or one indexpath 22 times? - Paulw11