title: Correct subclassing and reusing of UITableViewHeaderFooterView
body: <p>I have a UITableView where I have section headers that can be tapped to expand or collapse the section. In my particular example each section only has one row, which is either visible (section expanded) or hidden (section collapsed). 
  As section header i'm using  custom UITableViewHeaderFooterView  - HeaderAccountView.  I created *.xib file at Interface Builder , and set it custom class to my HeaderAccountView (still at IB field).</p>
  
  <p>There are no any changes to  <code>init</code> method or smth like this in my HeaderAccountView.h and HeaderAccountView.m files - only some functions to highlight self (selected section) etc.</p>
  
  <p>in my main ViewController .m file</p>
  
  <pre><code>- (void)viewDidLoad
        {
        [super viewDidLoad];
        .........
        .........
  
         UITableView *tableView = (id)[self.view viewWithTag:1];
         UINib *nib= [UINib nibWithNibName:@"HeaderAccountView" bundle:nil];
         [tableView registerNib:nib forHeaderFooterViewReuseIdentifier:@"HeaderCell"];
  
  
        } 
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>  - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
           HeaderAccountView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HeaderCell"];
        if (headerView==nil)
        {            headerView = [[HeaderAccountView alloc]
               initWithReuseIdentifier:@"HeaderCell"];
         }
     return headerView;
   }
  </code></pre>
  
  <p>when i'm running project everything going OK - sections load with needed data in it, when section receive tap - it highlights (like standard cell).</p>
  
  <p>But when i'm scrolling away tableview to bottom for example from selected highlighted section,  and this highlighted section already is not visible at view - that section  that just appeared from bottom - already highlighted!</p>
  
  <p>I understand that its because it creates new instance of my HeaderAccountView  with property <code>BOOL selected</code> set to YES.  </p>
  
  <p>But I'm new to objective-c (and coding) and don't understand how to correct resolve this.</p>
  
  <p>I tried to use <code>prepareForReuse</code> method of my custom UITableViewHeaderFooterView like this</p>
  
  <pre><code>  HeaderAccountView.m:
    -(void) prepareForReuse
    {
        self.selectedBackground.alpha = 0;
    }
  </code></pre>
  
  <p>It works better - but now i have another issue - when i returning to my first (truly) selected and highlighted section - it obviously don't highlight.</p>
  
  <p>Thanks  for any help and sorry if it elementary question.</p>