I wonder how to add UI elements programatically to existing nib files.
If I create a view programatically in loadView method and I add code like the following, the label displays correctly.
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0,2,150,100)];
[self.view addView:lbl];
But how to add the label to an existing nib file?
As Paul.s pointed out, you need to perform your custom code in
viewDidLoadmethod.From Apple documentation.
So, in your controller you could do this:
Why do you do this? Because here you are sure that view has loaded in memory and outlets has been set correctly.
On the contrary, about
loadViewmethodAn example could be:
I suggest you to read View Controller Programming Guide for iOS.
Hope it helps.