4
votes

I'm trying to understand why it seems to matter in what order I reload sections of my UITableView

If I reload like this:

// Reload section 1
[self.groupDetailsTableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];

// Reload section 0
[self.groupDetailsTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

There is no issue, but if I reload in opposite order (section 0 first and then section 1) I get an error:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. 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 (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

However If I do it like this, there is no error:

[self.groupDetailsTableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withRowAnimation:UITableViewRowAnimationFade];
2
If the number of items in section 0 changed, you would see precisely the behavior you describe. You can't update section 1 if section 0 has data source responses that don't match the table. You should reloadSections for all sections with any changes at the same time. Either that or insert and remove rows as you go along. - Rob

2 Answers

9
votes

I think there is a problem in the UITableview update; you are loading the section 1 table while section 0 is getting reloaded. I would suggest you use the [tableview beginUpdates] and [tableview endUpdates] methods right before and right after reloading, and the problem should disappear.

If not, then tell me. Hope this helps.

1
votes

Try this

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:NO];