title: UITableView selected cell doesn't stay selected when scrolled
body: <p>I'm having problems with table view cells not keeping their "selected" state when scrolling the table. Here is the relevant code:</p>
  
  <pre><code>@property (nonatomic, strong) NSIndexPath *selectedIndexPath;
  
  -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      self.selectedIndexPath = indexPath;
      //do other stuff
  }
  
  -(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      MyCustomCell_iPhone* cell = [tableView dequeueReusableCellWithIdentifier:@"MyCustomCell_iPhone"];
  
      if (cell == nil)
          cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell_iPhone" owner:self options:nil] objectAtIndex:0];
  
      if ([indexPath compare: self.selectedIndexPath] == NSOrderedSame) {
          [cell setSelected:YES animated:NO];
      }
  
      return cell;
  }
  </code></pre>
  
  <p>And for the cell:</p>
  
  <pre><code>- (void)setSelected:(BOOL)selected animated:(BOOL)animated
  {
      [super setSelected:selected animated:animated];
  
      if (selected) {
          self.selectedBg.hidden = NO;
      }else{
          self.selectedBg.hidden = YES;
      }
  }
  
  - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
  {
      [super setHighlighted:highlighted animated:animated];
  
      if (highlighted) {
          self.selectedBg.hidden = NO;
      }else{
          self.selectedBg.hidden = YES;
      }
  }
  </code></pre>
  
  <p>How can I get the selected cell to stay highlighted? If I scroll it off the screen, when it scrolls back on the screen it appears in its unselected state (with its selectedBg hidden).</p>
  
  <p>EDIT:
  Removing the setHighlighted method from the cell fixes the issue. However that means that I get no highlighted state when pressing the table cell. I'd like to know the solution to this.</p>