title: UITableViewCell - how to reset content before reusing
body: <p>There's an annoying bug that I can't fix.</p>
  
  <p>I have a <code>CustomCell</code>, and in it I have a subview that changes it's color according to object's value.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *cellIdentifier = @"CustomCell";
  
      CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
  
      if (cell == nil) {        
          cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
      }
  
      MyObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
  
      if ([object.redColor isEqualToNumber:[NSNumber numberWithBool:YES]]) {
          cell.colorView.backgroundColor = [UIColor redColor];
      }
      else {
          cell.colorView.backgroundColor = [UIColor clearColor];
      }       
  
      return cell;
  }
  </code></pre>
  
  <p>This is all working fine except when I delete a row with <code>redColor = YES</code> from the tableview, and I scroll to show rows that was not visible. The first row that becomes visible (first row that reuses the reusable cell) has red color, even though that row is <code>redColor = NO</code>. And if I scroll again and hide the cell and then show it again, color is set to clearColor, the way it should be.</p>
  
  <p>I think this is because it's reusing the cell that has just been deleted.
  So I'm trying to reset cell's content before reusing.
  In <code>CustomCell.m</code></p>
  
  <pre><code>- (void)prepareForReuse {
      [super prepareForReuse];
  
      self.clearsContextBeforeDrawing = YES;
      self.contentView.clearsContextBeforeDrawing = YES;
      self.colorView.backgroundColor = [UIColor clearColor];
  }
  </code></pre>
  
  <p>But this is not working.
  Apple Doc says</p>
  
  <blockquote>
    <p>The table view's delegate in tableView:cellForRowAtIndexPath: should always reset all content when reusing a cell.</p>
  </blockquote>
  
  <p>What is the proper way to reset content? Do I have to remove subviews from the superview?  </p>
  
  <p>Thanks in advance</p>