title: UITableViewCell reuse with custom UIView as a component causing "caching" issues
body: <p>I'm creating a view which comprises of a UITableView with customised cells - I'm overriding <code>drawRect</code> in my custom view.  I've tried overriding UITableViewCell and adding my custom view as an IBOutlet, I've tried not overriding it and just referring to it by <code>[[cell subviews] objectAtIndex:0];</code> both yield the same results.</p>
  
  <p>When I first look at the view, all is fine.  If I scroll slowly, all is fine.  As soon as I scroll quickly the reused cells are clearly not re-drawing because I end up with the custom drawing, being wrong for the particular cells.</p>
  
  <p>The cell configuration method...</p>
  
  <pre><code>- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"DialogCell"];
  MaskedRoundedCornerDIalogCell* dialogCell = (MaskedRoundedCornerDIalogCell*)[[[cell contentView] subviews] objectAtIndex:0];
  [dialogCell setPadding:10];
  if (indexPath.row % 2 == 0) {
      [dialogCell setAlignLeft:YES];
      [dialogCell setMaskTopLeftOnly];
      [[dialogCell textContent] setText:@"LEFT ALIGNED TEXT"];
      [[dialogCell textContent] setTextAlignment:NSTextAlignmentLeft];
  } else {
      [dialogCell setAlignLeft:NO];
      [dialogCell setMaskBottomRightOnly];
      [[dialogCell textContent] setText:@"RIGHT ALIGNED TEXT"];
      [[dialogCell textContent] setTextAlignment:NSTextAlignmentRight];
  }
  return cell;
  }
  </code></pre>
  
  <p>My Custom drawing code in my MaskedRoundedCornerDIalogCell implementation (A class which extends UIView and is added to the UITableViewCell):</p>
  
  <pre><code>- (void) drawRect:(CGRect)rect {
  
  int maxWidth = rect.size.width - 50;
  CGRect container;
  if (_alignLeft) {
      container = CGRectMake(rect.origin.x + _padding, rect.origin.y + _padding, maxWidth - (2* _padding), rect.size.height - (2*_padding));
  } else {
      container = CGRectMake((rect.size.width - _padding) - (maxWidth - (2* _padding)), rect.origin.y + _padding, maxWidth - (2* _padding), rect.size.height - (2*_padding));
  }
  
  UIRectCorner roundedCorners;
  if (!_maskTopLeft) {
      roundedCorners = roundedCorners | UIRectCornerTopLeft;
  }
  if (!_maskTopRight) {
      roundedCorners = roundedCorners | UIRectCornerTopRight;
  }
  if (!_maskBottomLeft) {
      roundedCorners = roundedCorners | UIRectCornerBottomLeft;
  }
  if (!_maskBottomRight) {
      roundedCorners = roundedCorners | UIRectCornerBottomRight;
  }
  UIBezierPath* containerBezierPath = [UIBezierPath bezierPathWithRoundedRect:container byRoundingCorners: roundedCorners cornerRadii:CGSizeMake(25.0F, 25.0F)];
  
  [[UIColor lightGrayColor] setFill];
  [containerBezierPath fillWithBlendMode: kCGBlendModeNormal alpha:1.0f];
  }
  </code></pre>
  
  <p>The way it looks when I first launch it:
  <a href="https://i.stack.imgur.com/4DVAz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4DVAz.png" alt="Correct Layout"></a></p>
  
  <p>The way it looks after scrolling a few times:
  <a href="https://i.stack.imgur.com/gCx4a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gCx4a.png" alt="enter image description here"></a></p>
  
  <p>Any advice, gratefully received...</p>