The property label is of type UILabel and is an outlet in UIViewController.
Why does the following work :-
[window addSubview:viewController.view];
[viewController.label setText:@"New Label"] ;
and the reverse sequence of statements doesn't change the default text in the label:
[viewController.label setText:@"New Label"] ;
[window addSubview:viewController.view];
Isn't view loaded from the UI elements attached to the UIViewController ?
From stackoverflow
-
A view controller creates or loads its view when it's first requested, either from a NIB or via the
loadViewmethod. And in most cases, the associated subviews are also only created when the main view is loaded. That means thatviewController.labelisniluntil you've first tried to accessviewController.view.So if you try to set the label text first, you're actually just sending that message to
nil, which is why it doesn't appear to have taken effect.
0 comments:
Post a Comment