UITableViewCell problem with ghost subview when performing reloadData
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.tex开发者_运维问答t = @"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?
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
精彩评论