views:

27

answers:

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!

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?

A: 

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

http://stackoverflow.com/questions/455553/what-is-nsstring-sizewithfontforwidthlinebreakmode-good-for

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

forgot to post the link... sorry

Aaron Saunders
viewRect? Cannot find such a thing in the API.
SaltyNuts
I meant "frame" not "viewRect"
Aaron Saunders
I would hope that the old view would just get destroyed when the cell is redrawn. Otherwise it's also a memory leak, in addition to other problems.
SaltyNuts