title: iPhone - Fixed (tableHeaderView) with grouped UITableView while scrolling cells
body: <p>I have a <code>UIView</code> with a grouped <code>UITableView</code> and I'd like the <code>UIView</code> to stay as a fixed <code>tableHeaderView</code>, rather than moving when scrolling the <code>UITableViewCell</code>'s. Therefore I'd like the cells to be behind the <code>UIView</code> when scrolling.</p>
  
  <p>This is the code I'm currently using to add my <code>UIView</code> to my <code>UIViewController</code>:</p>
  
  <p>Interface.h:</p>
  
  <pre><code>@interface MyAccountVC : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; {
      HeaderView *myHeaderView; // Inherits from UIView
      UITableView *tv;
  }
  
  @property (nonatomic, retain) IBOutlet UITableView *tv;
  @property (nonatomic, retain) HeaderView myHeaderView;
  </code></pre>
  
  <p>Implementation.m (in viewDidLoad):</p>
  
  <pre><code>// Set up the table's header view based on our UIView 'HeaderView' outlet.
  NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:nil options:nil];
  
  for (id currentObject in topLevelObjects) {
      if ([currentObject isKindOfClass:[UIView class]]) {
          self.myHeaderView = (HeaderView *)currentObject;
          break;
      }
  }
  
  CGRect newFrame = CGRectMake(0.0, 0.0, self.tv.bounds.size.width, self.myHeaderView.frame.size.height);
  self.myHeaderView.frame = newFrame;
  
  self.tv.tableHeaderView = self.myHeaderView;
  </code></pre>
  
  <p>Not sure if this is the best way of adding <code>myHeaderView</code> to the <code>UITableView</code>, but it seems to be working fine and I can simply add the above code to any <code>UIViewController</code> with a <code>UITableView</code> to re-use the header if need be.</p>
  
  <p>At the moment the header moves with the cells as I scroll, but I'd like the header to be fixed just below the top <code>UINavigationBar</code> while the cells move freely and behind the header. Please let me know if this all makes sense or whether you need more code in order to determine what I am trying to achieve.</p>