Reputation: 3347
I have a UILabel whose text I change from time to time. When I change the text, however, it doesn't erase the old text -- it re-draws on top of the old text and accumulates.
The UILabel is inside a UITableViewCell.
Has anyone encountered this problem? How do you fix it?
Upvotes: 0
Views: 1179
Reputation: 718
people! I`ve come over similar problem and was trying to create new question, but I decided to write inside this topic for not to make new one. So here is the my case:
I am trying to develop localised app, in which English words set to label normally by wordLabel.text = @"SomeNewWord";
but in case of Russian - new words are written above old ones. this case does not appear while I have some breakpoints to stop activity of the game. When there are no stopping factors the problem shows up. This happens only on iPhone with Russian language selected as default. on iPad everything goes well. I also tried to wordLabel.text
to nil
before assigning new word to the ULLabel. No reaction at all. The problem is present on both simulator and iPhone 4s for now.
my UILabel is made from storyboard and has @property (nonatomic, weak) IBOutlet UILabel *wordLabel;
UPDATE
after finding this post useful one at the bottom I`ve solved my problem. The answer was to UNCHECK Opaque in interface builder ...
Upvotes: 0
Reputation: 9285
This happen when u customize UITableViewCell
by [cell addSubView:UILabel]
method.
So let me explain it in some detail:
We use [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
method to get cell to use.
This method can one of two thing:
If it is fresh than no problem but if it is not than the controls which we have added by
[view addSubView:view]
method are already there and we add it again on same position like
stack of same controls.
We can solve it by two way:
code in such a way that add [UIView addSubView:UIView] only if it is fresh cell.
(I suggest this) Use subclass of UITableViewCell also call Custom UITableViewCell.
You will find many tutorial on this let me give u some:
Creating a Custom UITableViewCell
How To Design A Custom UITableViewCell From Scratch
If you are using storyboard than it is very easy:
Creating Table Views with Storyboards
Using Xcode Storyboards to Build Dynamic TableViews with Prototype Table View Cells
All the best...
Upvotes: 1