I have created an @property of UILabel and an outlet of UIViewController,
this is the code which works perfectly:
[window addSubview:viewController.view];
[viewController.label setText:@"Label1"];
but when we write this code in reverse order, it generates error:
[viewController.label setText:@"Label1"];
[window addSubview:viewController.view];
why it generate error?
Tarun Kumar
20-Nov-2015In most cases, the associated subviews only created when the main view is loaded. That means that viewController.label is nil until you've first tried to access viewController.view.
So if we will try to set the label text first, we are actually just sending that message to nil, which is why it doesn't appear to have taken effect