Posted By

saturngod on 02/10/11


Tagged

UITableView


Versions (?)

UITableview scroll


 / Published in: Objective C
 

URL: http://stackoverflow.com/questions/413055/setting-scroll-position-in-uitableview

  1. // Note: Member variables dataHasChanged and scrollToLast have been
  2. // set to YES somewhere else, e.g. when tapping 'Save' in the new-item view.
  3.  
  4. - (void)viewWillAppear:(BOOL)animated {
  5. [super viewWillAppear:animated];
  6. if (dataHasChanged) {
  7. self.dataHasChanged = NO;
  8. [[self tableView] reloadData];
  9. } else {
  10. self.scrollToLast = NO; // No reload -> no need to scroll!
  11. }
  12. }
  13.  
  14. - (void)viewDidAppear:(BOOL)animated {
  15. [super viewDidAppear:animated];
  16. if (scrollToLast) {
  17. NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:([dataController count] - 1) inSection:0];
  18. [[self tableView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  19. }
  20. }

Report this snippet  

You need to login to post a comment.