Dheeraj Gembali
Dheeraj Gembali

Reputation: 63

Assertion failure in -[UITableView _endCellAnimationsWithContext:] Getting Core Data error while trying to update tableview

The application uploads the photos to the server.

When the user selects some photos for upload, the photos' info is saved to core data. A tableview is populated showing the list of photos using fetchedResultsController.

The tableview has sections for ongoing uploads, photos in queue and finished uploads and is updated accordingly based on the status.

But now when I'm trying to add another set of photos for upload, by selecting again, while the previous set is still uploading, I get the following error.

And the tableview goes blank after this. I cannot see anything in the tableview.

CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of rows in section 1.  The number of rows contained in an existing section after the update (96) must be equal to the number of rows contained in that section before the update (62), plus or minus the number of rows inserted or deleted from that section (21 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

Upvotes: 0

Views: 2322

Answers (1)

Gordon Dove
Gordon Dove

Reputation: 2577

What is happening here is that you're first update has inserted 21 cells, and added to the model. The table view updates it's internal model by calling tableView:numberOfRowsInSection:, which should return 83 ( 62 + 21), but your second update has added some more items to the model, so it actually returns 96.

This normally happens either because you're calling UIKit operations outside the main thread ( very bad), or you've made a change to your model without updating the tableview in the same function.

Upvotes: 1

Related Questions