For completely programmatically created UIView/UIViewController, what should be in loadView vs viewDidLoad? <p>For experimentation purposes, I am trying something completely in code.</p> <p>I have a custom root <code>UIView</code>/<code>UIViewController</code> subclass pair called RootView and RootViewController respectively.</p> <p>I also have a <code>GLKView</code>/<code>GLKViewController</code> subclass pair called RenderView and RenderViewController.</p> <p>Both <code>UIViewController</code> subclasses create their managed views in their <code>loadView</code> overrides.</p> <p>Setting up the main RootViewController/RootView is simple. In my AppDelegate subclass, I create the main window and assign the rootViewController proeprty like so...</p> <pre><code>#import "AppDelegate.h" #import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CGRect screenBounds = [[UIScreen mainScreen] bounds]; // Set up the window UIWindow* mainWindow = [[UIWindow alloc] initWithFrame:screenBounds]; mainWindow.rootViewController = [RootViewController new]; self.window = mainWindow; [mainWindow makeKeyAndVisible]; return YES; } @end </code></pre> <p>The RootView appears on screen exactly as one would expect.</p> <p>What I'm wondering however is about view hierarchy initialization. RootViewController has a property to hold an instance of RenderViewController, and its RenderView will be (initially) placed in the frame which is stored in a second property of RootViewController called renderViewFrame.</p> <p>My question is where is the proper place to set up that hierarchy?</p> <p>The documentation states that's exactly what <code>UIViewController</code>'s <code>loadView</code> is for so this is what I'm doing there...</p> <pre><code>- (void)loadView { self.view = [[RootView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Set up the RenderViewController RenderViewController* renderViewController = [RenderViewController new]; [self addChildViewController:renderViewController]; renderViewController.view.frame = self.renderViewFrame; [self.view addSubview:renderViewController.view]; self.renderViewController = renderViewController; } </code></pre> <p>...and it works, but I've seen some people say no, I should move everything relating to creating RenderView/RenderViewController to RootViewController's <code>viewDidLoad</code> and not <code>loadView</code>, but no one can say why. I mean it is part of the hierarchy and that's specifically what <code>loadView</code> is for.</p> <p>And if I'm right, then why would I/anyone need to use <code>viewDidLoad</code> at all if we're already doing initialization in <code>loadView</code>, or is that just an artifact from when memory could unload the views all the way back in iOS6?</p>