How to reset the scroll position of a UITableView?

I would like to completely reset the scroll position of a UITableView, so that every time I open it, it is displaying the top-most items. In other words, I would like to scroll the table view to the top every time it is opened.

I tried using the following piece of code, but it looks like I misunderstood the documentation:

- (void)viewWillAppear:(BOOL)animated {
    [tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:NO];
}

Is this the wrong approach here?

Answers


August got the UITableView-specific method. Another way to do it is:

[tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];

This method is defined in UIScrollView, the parent class to UITableView. The above example tells it to scroll to the 1x1 box at 0,0 - the top left corner, in other words.


Need Your Help

Regular expression for a range between -5.00 To 10.00

regex

I am trying to write a regular expression for .NET application that can accept values between -5.00 To 10.00 (Numeric decimal, up to two decimal places).

How to detect multiple static body in box2d

cocoa-touch cocos2d-iphone box2d-iphone

I have a some issue regarding multiple detection of static bodies.