views:

16

answers:

2

I have a UILabel in a UITableCell, and when I make the label's background transparent, I get these strange ghost characters (see image below), and it looks terrible. Here's my code:

Left:

UILabel *unreadLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 7, 25, 25)];
unreadLabel.text = [NSString stringWithFormat:@"%d", source.unreadCount];
unreadLabel.textColor = [UIColor colorWithWhite:100.0f/255.0f alpha:1.0];
unreadLabel.font = [UIFont systemFontOfSize:11.0f];
[cell addSubview:unreadLabel];
[unreadLabel release];

Right is the same as the left but with this added:

unreadLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0];

UnreadCount is a NSInteger.

alt text

+1  A: 

This happens when you draw text over and over again. My first thought is, it looks like you have a cell reuse bug, whereby you're not clearing everything when you reuse cells. If you were to take out cell reuse, and just allocate a new cell every time, I bet this doesn't show. If this is the case, then definitely look at how you're clearing a cell before you reconfigure it, and ensure said label is being handled properly and not ignored.

jer
+1  A: 

You're adding a UILabel to the cell every time you use the cell. However, cells are reused, so every time a cell is reused, you're just adding a new label to it. You need to adjust this so you only add a label when you create the cell, and instead just retrieve the already-existing label (perhaps by giving it a tag and using -viewWithTag:) on subsequent reuses of the cell.

Kevin Ballard