Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView reload sections order matters?

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];
like image 724
Peter Warbo Avatar asked Dec 26 '22 02:12

Peter Warbo


1 Answers

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.

like image 189
iEinstein Avatar answered Jan 11 '23 13:01

iEinstein