Scroll to top of UITableView by tapping status bar Scroll to top of UITableView by tapping status bar ios ios

Scroll to top of UITableView by tapping status bar


You get this for free, but you should check that the scrollsToTop attribute of your UITableView is YES.

When this does NOT work is when you have a UIScrollView (or descendant class like UITextView) object embedded inside another UIScrollView class (like UITableView). In this case, set scrollsToTop on the embedded UIScrollView class to NO. Then the tap-the-status-bar behavior will work.


If you came from Google and need a complete checklist:

  1. Check that you've set scrollsToTop=YES (per Mark's suggestion) on your UITableView
  2. Make sure that you've set scrollsToTop=NO on all OTHER UITableViews / UIScrollViews / UITextViews in your window, so that they're not intercepting the click. I've found myself printing out all the views in my window many times to debug this...
  3. Make sure that your table view is at 0/0 (x/y coordinates) within the window - this is how the system knows that it should pass the message


Using the information given in other answers, I added the following code to my UITableViewController get it to work:

- (void)viewDidLoad{    [super viewDidLoad];    for (UITextView *view in self.view.subviews) {        if ([view isKindOfClass:[UITextView class]]) {            view.scrollsToTop = NO;        }    }    self.tableView.scrollsToTop = YES;}

This looks through all the views in the UITableViewController's hierarchy and turns off scrollsToTop on all the UITextViews that were intercepting the touch event. Then, ensured the tableView was still going to receive the touch.

You can mod this to iterate through other UITableViews / UIScrollViews / UITextViews that may be intercepting as well.

Hope this helps!