Wednesday, April 20, 2011

UITableView - scroll to the top

Hi,

In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section number 5.

So I get an exception, when I call:

[mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];

Is there another way to scroll to the top of table view?

From stackoverflow
  • UITableView is a subclass of UIScrollView, so you can also use:

    [mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
    
    Ilya : Thank you, this helped.
  • [mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; works, but if I turn the animation to "NO" it stops working...

0 comments:

Post a Comment