logixologist
logixologist

Reputation: 3834

Issue with overlapping text: iOS7

I normally post source code and examples of UI but I think its more related to an iOS7 change and I cant see it being a code bug (yet). I would have to post so much code and UI that it would be counter productive. So here is my best non-visual description:

Since upgrading a project to iOS7 I am finding that if I put call to change a UILabel or calling setText of a UIButton in a ViewDidAppear or ViewWillAppear it puts the new text right on top of the old text.

Since developing for iOS I have never had to do anything different. If I do this:

lblMyHours.text = @"12";

It shouldnt just throw that on top of my existing label.

This especially happens inside of a UITableView where I have created an iVar for a UILabel thats in a UITableViewCell. If a user makes an adjustment to a value after clicking on a cell (it takes them to a detail screen to edit), when I pop back I have it recalculate in ViewDidAppear. In that recalculating I am resetting a label like the above. But it doesnt clear out the old.

Upvotes: 0

Views: 285

Answers (2)

Kamran Khan
Kamran Khan

Reputation: 1366

There are two way to achieve this, one you are already doing and as @Guilherme rightly pointed out. The other way is to create a custom tableview cell and put the UILabel property in there. As for the viewDidAppear scenario, you can create a uilabel in ther .h file (in the @interface declaration) and then initialize it in ViewDidLoad method and simple use in ViewDidAppear method without having to declare it again.

I would suggest that you follow the way I described for ViewDidAppear issue, and for the UITableView issue, search for UILabels in subview of the cell everytime cellForRowAtIndex method is called and remove it from the subview, something like this before adding a new label

for(UIView *view in cell.subviews)
{
    if([view isKindOfClass:[UILabel class]])
    {
         [view removeFromSuperview];
    }
}

Hope this helps.

Upvotes: 1

Guilherme
Guilherme

Reputation: 7949

You might be adding a new label every time you return a new cell. You should just replace the text of the current label instead.

Upvotes: 1

Related Questions