title: Why does UITableView contentOffset change when using segmented control?
body: <p>I have a <code>UITableView</code> which has a segmented control in its navigation bar. I am using the same table view to show 3 different sets of data, based on the selected index of the segmented control. I am now trying to preserve the scroll position for each segment option, so that it appears that there is one table for each segment option (i.e. the results of each selection have independent scroll positions).</p>
  
  <p>To do this, I am storing one <code>CGPoint</code> variable for each state, which is <em>set</em> to the <code>contentOffset</code> when the selected segment index changes. The variable is <em>used</em> to set the table view's content offset upon segment change.</p>
  
  <p>However, it seems like the <code>contentOffset</code> value changes when the selected segment index changes without any visible change to the position within the table. It is like the 0-position of the content offset is moving, which makes my stored values now wrong. </p>
  
  <p>When my controller contains the following methods:</p>
  
  <pre><code>override func viewDidLoad() {
      // set up the view here...        
  
      print(tableView.contentOffset)
  }
  
  @IBAction func selectedSegmentChanged(sender: AnyObject) {
      print(tableView.contentOffset)
  
      // code to change the data shown in the table view...
  }
  </code></pre>
  
  <p>I get the following logged when the view loads:</p>
  
  <blockquote>
    <p>(0.0, 0.0)</p>
  </blockquote>
  
  <p>but after changing the segment I get:</p>
  
  <blockquote>
    <p>(0.0, -64.0)</p>
  </blockquote>
  
  <p>All states show the table view scrolled to the exact same position, that is - at the top.</p>
  
  <p>This behaviour is preventing me from being able to store the scroll position properly, as the 'meaning' of the content offset seems to be changing.</p>
  
  <hr>
  
  <p>Edit: the content offset is in fact being adjusted between <code>viewDidLoad()</code> and <code>viewDidAppear()</code>, most likely due to a content <em>inset</em>. So I am now storing the content offset value the first time <code>viewDidAppear()</code> is called.</p>