tags:

views:

1241

answers:

6

Hello,

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 :(

A: 

I am experiencing something similar. I have a UILabel where updating text is fine, but the previous text is not removed, so the text is overlapping and messy. I am using [myLabel setText:somemessage] and the UILabel has the options 'opaque' and 'clear context before drawing' enabled. Any ideas?

Read my answer below.
JoePasq
A: 

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

A: 

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 ..

A: 

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.

Shoaibi
A: 

I have posted what I think is something simlar but don't think it is the exact same....If anyone wants to have a look to help with the solution, that would be appreciated! Thanks!

http://stackoverflow.com/questions/1327031/duplicate-rows-in-tableview-on-uitableviewcell

SKayser
+1  A: 

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!

JoePasq