-1

I am trying to change the value of the label here.

Can anyone explain me why the following method call:

 [_detailLabel setStringValue:@"this is new label value"];

works if I make the call from viewDidLoad and viewDidAppear methods, but it doesn't work in the method that I created:

-(void)changeLabelValue : (NSString *) newVal {
    [_detailLabel setStringValue:@"this is new label value"];
    NSLog (@"Hello from changeLabelValue method");
}

Please note that when I call this method from anywhere from my code, the NSLog message IS displayed but the value of the label is not changed...

Any help is deeply appreciated.

Pointing me to resource where I can learn more on this subject will also do the trick, and will be also deeply appreciated.

Regards, John.

user2417624
  • 653
  • 10
  • 32
  • When do you call `changeLabelValue:`? Is it after the view controller has been displayed or before? – rmaddy Aug 21 '15 at 18:32
  • I was calling it from the observeValueForKeyPath, and it didn't worked. Now when I do call it from viewDidLoad works. Please type your comment as an answer so I can accept it. – user2417624 Aug 21 '15 at 18:39

1 Answers1

2

Make sure that changeLabelValue: is being called after viewDidLoad is called (or the view controller has been displayed). If you call it before the view is loaded, _detailLabel will be nil since it hasn't been loaded yet.

rmaddy
  • 314,917
  • 42
  • 532
  • 579