I have a table with expendable sections. Sort of like a "plus" in tree on Windows. When user taps that plus button on a section, that section expends/collapses, showing or hiding cells in it. Here is the viewForHeaderInSection:
// Open/close on tap block
[headerView setOpenOnTapBlock:^(BOOL open) {
NSInteger numberOfRowsToChange = [changedRows count];
NSMutableArray *indexPathsToChange = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < numberOfRowsToChange; i++) {
[indexPathsToChange addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
if (indexPathsToChange.count) {
[self.redSection[section] setOpen:open];
[self.tableView beginUpdates];
if (open) {
[self.tableView insertRowsAtIndexPaths:indexPathsToChange
withRowAnimation:UITableViewRowAnimationMiddle];
} else {
[self.tableView deleteRowsAtIndexPaths:indexPathsToChange
withRowAnimation:UITableViewRowAnimationMiddle];
}
[self.tableView endUpdates];
}
}];
Now, all expending-collapsing works just fine, except for 1 small detail.
Consider a table loaded with all sections expanded initially. If the table's content position is such that 3rd (for example) section header is right on the bottom, and "collapse" is tapped, 4th section header would now draw right below the 3rd header. And it does, however there is some strange animation happening - that 4th header is added dropping from approximately middle of the table view. Any ideas how to avoid this?
Note: this only happens before the table has been scrolled trough. After that, all works good. Appreciate any suggestions.