Reputation: 888
I have a UITableview
with 40 to 50 sections. It is expandable tableview when ever tapped on Section header am expanding that corresponding section if already expanded it will close. My issue is when ever I tapped on Section header requesting server for data and received data from server my Tableview automatically scrolled to top and this is happend after 20th section only. I could not understand whats going wrong.
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:self.selectedIndexPath.section];
[self.tableview reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];
Upvotes: 1
Views: 489
Reputation: 730
If you do something which changes the height of some of the cells the table will scroll to a different position after the reload. If you want the tableview to scroll to the top of the tapped section once the load has finished, what about something like:
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section];
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];
NSIndexPath *sectionPath = [NSIndexPath indexPathForRow:NSNotFound inSection:section];
[self.tableView scrollToRowAtIndexPath:sectionPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
Upvotes: 1