title: Background color change on table view cell tap in IOS
body: <p>I have a view controller that has a UITableViewController as its main view. In the function - tableView:cellForRowAtIndexPath: I create a custom view for my cell with the following code.</p>
  
  <pre><code>static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                                          CellIdentifier];
  
  // Configure the cell...
  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:CellIdentifier];
  }
  
  
  cell.backgroundView = [[UIView alloc] init];
  </code></pre>
  
  <p>I then add my own custom views to cell.backgroundView. However, when I tap a cell the cell becomes completely gray. No where in my code do I specify that this should happen. To do some testing I added some text to the standard part of a cell as follows.</p>
  
  <pre><code>cell.textLabel.text = @"TEST";
  </code></pre>
  
  <p>When I ran this I saw both my custom view and the 'TEST' label. When a cell was pressed, the gray screen appeared and this time 'TEST' was visible and my custom view still not visible. My guess is that some other measure has to be taken to ensure custom views are visible. I was using the tableView:didSelectRowAtIndexPath: function to register taps but oddly this function is called for all tap events except the first one. In addition, I tried to set the background color here but it didn't work.</p>
  
  <pre><code>- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
      UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
      newCell.backgroundColor = [UIColor whiteColor];
  
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>