title: How to stop UITableView cell is overwriting the contents?
body: <p>I am using a UITableView and I'm noticing that the cells in my tableview are getting progresively bolder as I scroll, it is overwriting the contents and I want to stop this but can't see where I'm going wrong.</p>
  
  <p>On my UITableView, for some reason when I scroll the contents of the tableview get messed up with the the manually created UILabel.</p>
  
  <p>I require a manual UILabel because I need to have custom cells later on.</p>
  
  <p>As I scroll up and down, the labels get progressively bolder and bolder; they always overlap and sometimes even affects rows lower down (even before they are in the viewport).</p>
  
  <p>If I keep doing it, the cell contents become unintelligable.</p>
  
  <p>This only happens if there the backgroundColor is not set as <code>clearColor</code>.</p>
  
  <p>I have attempted <code>[cellLabel setClearsContextBeforeDrawing:YES];</code> and <code>[self.tableView setClearsContextBeforeDrawing:YES];</code>  to no effect.</p>
  
  <p>If I use <code>cell.textLabel.text</code> then the problem seems to go away.</p>
  
  <p>Code and an image sample follows.</p>
  
  <pre><code>  // Simple table view
      - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
      {
          static NSString *CellIdentifier = @"Cell";
  
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
          }
  
          // Configure the cell...
          //[self configureCell:cell atIndexPath:indexPath];
  
  
          NSString *txt = @"Product";
  
  
          //cell.textLabel.text = txt;
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
  
          UIView *cellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, cell.frame.size.height)];
  
          UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
          [cellLabel setText:txt];
          [cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
          [cellLabel setBackgroundColor:[UIColor clearColor]];
  
          [cellView addSubview:cellLabel];
          [cellLabel release];
          [cell.contentView addSubview:cellView];
          [cellView release];
  
  
          return cell;
      }
  
  
  Image follows;
  
  
  ![image of uitableview][1]
  
  
    [1]: http://i.stack.imgur.com/5lNy6.png
  
  
  // Edit to include context
  
  I am using a dictionary to display the contents of the UITableViewCells.
  
  I have attempted to do the following;
  
      - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
      {
          static NSString *CellIdentifier = @"Cell";
  
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          if (cell == nil) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  
              [self configureCell:cell atIndexPath:indexPath];
          } // end if
  
  
          // Configure the cell...
          //
         // Moved to inside the cell==nil        
  
          return cell;
      }
  
  -(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
  {
  
      // Get the txt from the Dictionary/Plist... *removed due verboseness*
  
      UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
      [cellLabel setText:txt];
      [cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
      [cellLabel setBackgroundColor:[UIColor clearColor]];
  
      [cell.contentView addSubview:cellLabel];
      [cellLabel release];
  }
  </code></pre>
  
  <p>This, although it fixes the problem of overwriting -- it causes a problem -- it makes labels repeatedly appear in totally random places  -- the following is just an example, other fields and labels also repeat.</p>
  
  <p>See picture below;</p>
  
  <p><img src="https://i.stack.imgur.com/nYUAD.png" alt="repeating labels in uitableview"></p>