2

I have some UILabel objects in my app, and I change their value when a button is pressed. It works fine in the simulator and on old iPhones, but If I try it on an iPhone 4, the previous text of the label doesn't disappear, it shows behind the the new text (well, sometimes it disappears and only the correct text appears, but most of the times it doesn't work right).

This is the code (it's a method that only does that, lehenPantalla is a UIViewController, and the variables used to set the text are ints passed as parameters):

self.lehenPantalla.firstPlayerSet.text = [NSString stringWithFormat:@"%d",localFirstPlayerSet];
self.lehenPantalla.secondPlayerSet.text = [NSString stringWithFormat:@"%d",localSecondPlayerSet];
self.lehenPantalla.firstPlayerGames.text = [NSString stringWithFormat:@"%d",localFirstPlayerGames];
self.lehenPantalla.secondPlayerGames.text = [NSString stringWithFormat:@"%d",localSecondPlayerGames];

Is this a common error? I don't know if this happens because the phone is an iPhone 4 or because it's using iOS 5.1 (the other phone is running iOS 4).

Daniel
  • 23,129
  • 12
  • 109
  • 154
XaitormanX
  • 891
  • 1
  • 11
  • 22
  • How are the labels created in the nested vc? are they retained props? are they linked from a nib? – shawnwall Apr 29 '12 at 16:14
  • They are IBOutlets linked from a nib – XaitormanX Apr 29 '12 at 16:27
  • I can tell you it's not a bug, and not common. I'm guessing that you have a transparent background behind ``UILabel``? And ``redraw`` might not be correctly handled in the background view. You might want to post more about your view hierarchy. – He Shiming Apr 29 '12 at 17:08
  • Thanks for the answer No, the UILabels are placed in a solid UIView. Here is my hierarchy: lehenPantalla is a view controller with some buttons and a UIView in its view. In the UIView that is inside the main view, there are some labels(the ones appearing in the code), and those labels are linked to the viewController. So the labels I'm trying to change are inside a secondary view, maybe that is the problem? (I'll try to move them out of that secondary view) – XaitormanX Apr 29 '12 at 18:32
  • Don't pretend for this to be an answer, but I have absolutely the same setup and problem. After banging my head, I just went with UIButton instead of UILabel (Custom and UI interaction disabled). That worked across all of my tested devices/simulators. Anyway it looks like a bug, noway it is not? – Stanislav Dvoychenko May 24 '12 at 23:35
  • This also seems to happen when the label's background is not set and you subsequently change the text: http://stackoverflow.com/a/2325813/14955 – Thilo Oct 03 '14 at 11:15

2 Answers2

0

Given this sounds like it is appearing in ios5 and not before, perhaps it is related to view controller containment which changed in ios5. Events such as viewDidLoad/willAppear etc aren't necessarily called properly without proper containment.

Have you called addChildViewcontroller to add lehanPantella?

Community
  • 1
  • 1
shawnwall
  • 4,549
  • 1
  • 27
  • 38
  • No, in the main ViewController (the one that has lehenPantalla as a member variable) has a UIView inside it's view, linked to the viewcontroller as a IBOutlet (called testView). Then I have a method that creates a LehenPantallaViewController, and adds it's view as a subview to the view that is linked to the main ViewController. the code is something like this: `self.lehenpantalla=[[LehenPantallaViewController alloc]init];` `[self.testView addSubview vc.view]` – XaitormanX Apr 30 '12 at 08:21
  • yes, so you are containing a view/vc inside your main vc. Try adding lehenpantella using addChildViewcontroller: so the view hierarchy is set up properly. – shawnwall Apr 30 '12 at 15:08
  • Ok, I'll have to change a great amount of code. I'll tell you if it works when I finish – XaitormanX Apr 30 '12 at 17:37
  • I finished. It didn't work :( BTW, one question about addChildViewController:. If I am adding another viewcontroller's view as a subview of a view that isn't my viewcontroller's main view, should I still call `[self addChildViewController:anotherVc];` ? – XaitormanX Apr 30 '12 at 19:30
  • no wouldn't call self then you would call addChild... on whatever the parent view of the containing view is. – shawnwall Apr 30 '12 at 21:27
  • but If the parent view Isn't a UIViewController but a UIView? UIView hasn't addChildViewController method – XaitormanX May 01 '12 at 08:16
0

I experienced the same problem with iPhone4/ios5. At the end just making the label non-Opaque (unchecking the Opaque checkbox in interface designer) solved the issue. Where I wanted this label to draw upon the background (with no transparency) I just had to put another label beneath it (same width, no content). Hope that might help.

Stanislav Dvoychenko
  • 1,303
  • 1
  • 15
  • 15