If you re-use view controllers, e.g. for subviews in a UITableViewController, then you can run into situations where any scrolling you did in a previous subview is preserved in the new one. While this may be fine for UITableView, it can be jarring for a UITextView or custom UIScrollView.

Here’s how to prevent it.

There’s a simple UIScrollView method you can invoke anytime a new view controller is displayed. I prefer to invoke it in the viewWillAppear method, so the UIScrollView is reset before it’s visible:

– (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.myView scrollRectToVisible:CGRectMake(0, 0, 1, 1)
        animated:NO];
}


That’s it! The scrollRectToVisible method tells the UIScrollView to make the CGRect parameter visible, which in the above example is a 1×1 square at (0,0) or “the top”.