1

I have added a custom UILabel to the contentView of my cell, depending on the state of the app, it turns bold or regular weight. For some reason when I do [tableView reloadData] to make it regular weight again, the bold version of the label remains visible, like this:

pesky ghosts! http://a.imageshack.us/img836/1732/screenshot2010080513050.png

See the pesky bit from the bold "7" still visible? It's like that for every cell, if it turns bold once, the "ghost" remains until the app quits.

The label is created this way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//.....

UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"my text here";
label.font = condition ? [UIFont boldSystemFontOfSize:12] : [UIFont systemFontOfSize:12];
label.numberOfLines = 1;
[label sizeToFit];  
[cell.contentView addSubview:label];
[label release];
//......
}

This did not happen when I used the cell's textLabel, but for other reasons I need to use a separate UILabel.

What could be causing these views to stay after reloading data?

SaltyNuts
  • 5,068
  • 8
  • 48
  • 80
  • Does it also happen when you scroll the table view? – JonB Aug 05 '10 at 17:42
  • No, it looks fine if I scroll. – SaltyNuts Aug 05 '10 at 18:21
  • it's actually very odd behaviour, because it looks like all subViews I add to the cell's contentView get layered over and over like this. When a view has an alpha channel, this really messes things up. For example, it kills antialiasing effect on any non-linear shapes and transparent png files, which start looking very ugly after several reloads. There must be some way to clear the content of the cell before redrawing it, you'd think this would be built-in behaviour. – SaltyNuts Aug 05 '10 at 20:12

1 Answers1

0

i think this question is what you might be looking for...

What is -[NSString sizeWithFont:forWidth:lineBreakMode:] good for?

it might be that your label's frame is incorrect so the old content is viewable

forgot to post the link... sorry

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80