John Brooks
John Brooks

Reputation:

UILabel text overlapping on update?

In my app I change the value of a text label from an initial value of 0 and increment it on a touch event. Sometimes, but not all the time, the new value will be overlayed over the 0, which is not cool..

This is the relevant code:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:1000];
label.text = qtyString;

I've tried removing the label from the view, then adding another with the new value, but it didn't affect the problem at all. When I scroll the cell (the labels are part of a table cell) out of the screen and back in, the labels display correctly. Oh, and I've also tried doing

[tableView reloadData];

And it works better, but if I select a cell and then scroll while it is higlighted it poops out on that cell.

Please help :(

Upvotes: 5

Views: 5070

Answers (6)

0oneo
0oneo

Reputation: 695

check the "clears graphics context" works for me, i carelessly deselected it at first~~

Upvotes: 19

user1105951
user1105951

Reputation: 2287

In my case, changing Opaque to NO solve the problem of updating the UILabel.text I create the uilabel in the awakeFromNib.

Upvotes: 0

fearmint
fearmint

Reputation: 5334

I had the same problem with UILabel's text getting all jumbled, I just read the other solutions, went to IB, then checked "Clear context before drawing", and that solved it!

Upvotes: 4

Shoaibi
Shoaibi

Reputation: 889

imho, the best way to go around this is to add an else to:

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}else {
    NSArray *cellSubs = cell.contentView.subviews;
    for (int i = 0 ; i < [cellSubs count] ; i++) {
        [[cellSubs objectAtIndex:i] removeFromSuperview];
    }
}

Hope this helps.

Upvotes: 0

johnny mast
johnny mast

Reputation:

Changing opaque doesnt change it altho it would have been logic. What you can do if giving your label an exact height .. This height will match your well height. If you are using

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    { return 80; //returns floating point which will be used for a cell row height at specified row index
    }

Like i did then make the height of the label 80 as well that will stop it ..

Upvotes: 0

Yanni
Yanni

Reputation:

Under your UILabel options UNCHECK 'opaque', that will fix it.

Upvotes: 6

Related Questions