简体   繁体   中英

UITableView does not scroll up every time I reload a tableview section

I have a table with multiple section headers. What I am trying to do is every time I click on one of the section headers, section and section rows get updated using following code

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationNone];

Now, the problem is sections are reloaded and they come up but the tableView does not scroll up on that. Say my header section that I want to expand is at the bottom of the visible screen, every time I click on section header, it expands below that and is not visible to the user until and unless user scrolls the screen himself. I want the view to scroll up so that user could see the expanded view on the screen.

Any ideas how can i do that or any sample code would be appreciated.

Thanks Vik

Use the scrollToRowAtIndexPath:atScrollPosition:animated: table view method to scroll the table as needed.

[self.tableView scrollToRowAtIndexPath:someIndexPath atScrollPosition: UITableViewScrollPositionTop  animated:YES];

Provide the appropriate indexPath. There are other options for the scroll position if 'top' isn't quite what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM