title: How to scroll to the top of a UITableView in iOS 7
body: <p>In iOS 7, I use the following code to scroll to the top of my <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:" rel="nofollow noreferrer">UITableView</a>. You have to account for the overlap of the translucent status bar and navigation bar.</p>
  
  <pre><code>[tableView 
      setContentOffset:CGPointMake(
          0.0, 
          -tableViewController.topLayoutGuide.length
      ) 
      animated:YES
  ];
  </code></pre>
  
  <p>This works only works <em>after</em> the first time you call it. On the first time you call it, my table gets scrolled much farther than it should, showing a lot of white space. Additionally, the <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html" rel="nofollow noreferrer">UIRefreshControl</a> appears frozen. You have to nudge the table a little to make it bounce back to the true top. Afterwards, you can call this code as many times as you want and it behaves as you'd expect it.</p>
  
  <p><img src="https://i.stack.imgur.com/aTbss.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/ifl8U.png" alt="enter image description here"></p>
  
  <p>I've tried other ways, but they all have problems. The iOS 6 way behaves just as oddly on the first call. Although it doesn't jump a huge amount on subsequent calls, they are not correct because it scrolls to 64.0 points below the top of the table because we forgot to account for the status and navigation bar.</p>
  
  <pre><code>[table setContentOffset:CGPointZero animated:YES];
  </code></pre>
  
  <p>I've also tried scrolling to the first cell, but it doesn't scroll to the very top in one call. It will only scroll up one page's worth every time you call it. </p>
  
  <pre><code>[tableView 
      scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] 
      atScrollPosition:UITableViewScrollPositionTop 
      animated:YES
  ];
  </code></pre>