title: UITableView's tableHeaderView height property is changed to strange values during load and rotation
body: <p>I have a custom UIView which I set to the tableHeaderView property of a UITableView during loadView:</p>
  
  <pre><code>headerView = [[MYViewClass alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
  [headerView sizeToFit];
  
  self.tableView.tableHeaderView = headerView;
  </code></pre>
  
  <p>The view draws incorrectly, with part of the view clipped and white space above the table.  When rotating the device the view almost disappears. On rotating back the view is now bigger that the space for the header and obscures some of the cells in the table.</p>
  
  <p>To troubleshoot I have overrode the setFrame method in my custom view class:</p>
  
  <pre><code>- (void) setFrame:(CGRect)frame {
      [super setFrame:frame];
      NSLog(@"%@ - %@", NSStringFromSelector(_cmd), NSStringFromCGRect(frame));
  }
  </code></pre>
  
  <p>I also put a break point on the NSLog statement so I could see what called the setFrame and I get some odd results that I can't explain and hope someone can shed some light on what is happening and why.</p>
  
  <p><strong>During loadView</strong>    </p>
  
  <pre><code>1. initWithFrame calls: setFrame: - {{0, 0}, {320, 120}}
  2. sizeToFit calls: setFrame: - {{0, 0}, {320, 109}}
  3. setTableHeaderView calls:  setFrame: - {{0, 0}, {320, 109}}
  4. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {320, 109}}
  5. _resizeWithOldSuperviewSize calls: setFrame: - {{0, 0}, {320, 65}}
  6. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {320, 65}}
  7. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {320, 65}}
  </code></pre>
  
  <p><strong>Rotating the device left</strong></p>
  
  <pre><code>1. _resizeWithOldSuperviewSize calls: setFrame: - {{0, 0}, {480, 0}}
  2. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {480, 0}}
  3. _resizeWithOldSuperviewSize calls: setFrame: - {{0, 0}, {480, 12}}
  4. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {480, 12}}
  </code></pre>
  
  <p><strong>Rotating the device right</strong></p>
  
  <pre><code>1. _resizeWithOldSuperviewSize calls: setFrame: - {{0, 0}, {320, 172}}
  2. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {320, 172}}
  3. _resizeWithOldSuperviewSize calls: setFrame: - {{0, 0}, {320, 160}}
  4. _adjustTableHeaderAndFooterViews calls: setFrame: - {{0, 0}, {320, 160}}
  </code></pre>
  
  <p>Which explains why my view looks truncated initially, then almost disappears and finally ends up overlapping the cells.  It appears that <code>_resizeWithOldSuperviewSize</code> is the culprit and what I don't understand is why it is being called and where it is getting these odd values from.</p>
  
  <p>I have a really rubbish work around by calling <code>[self.tableView.tableHeaderView sizeToFit]</code> in <code>viewDidAppear:</code> and <code>didRotateFromInterfaceOrientation:</code> which puts the frame back to the correct size but the redrawing is awful as both happen after the view is visible or after the rotation animation.  Trying to set this anytime before the view is visible causes <code>_resizeWithOldSuperViewSize</code> to set the frame back to these odd sizes.</p>