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?
This happen when u customize
UITableViewCellby[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:
OR
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 likestack 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…