I set views programmatically. Here is how I do that. Let’s say I have SettingsViewController.m
In this file I have two methods
-(void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.view = view;
[view release];
}
-(void)didViewLoad
{
// In that method I create some buttons labels etc
}
Is my approach correct ? To create the view in loadView method and buttons, labels etc in viewDidLoad method
To be honest it doesn’t really matter if you put the code for creating views in
viewDidLoadorloadView.viewDidLoadis called after the view is loaded, so will even be called if you are instantiating from a XIB. So that’s a good place to add extra views if you’re using a XIB. If you’re programatically creating the view like you are inloadViewthen you can put the creation of your buttons, labels, etc inloadVieworviewDidLoadand it won’t really make a difference –viewDidLoadis pretty much called straight afterloadViewruns anyway.Personally if I’m creating a view programatically using
loadViewthen I will put all of the view creation code in there rather than inviewDidLoad.