Force viewDidLoad to fire on iOS

Borut Tomazin picture Borut Tomazin · Oct 3, 2012 · Viewed 10.5k times · Source

I have two window app and while I present first window I would like the view in second window to load and prepare content for later in background.

I've tried to use method loadView but Apple says you should not call this method directly.

So far I've chosen to use the view's method userInteractionEnabled which actually implicitly calls viewDidLoad method.

Is there an elegant way to force ViewControllers viewDidLoad method to fire before it should naturally (when window is key and presented)?

Answer

Carl Veazey picture Carl Veazey · Oct 3, 2012

You can just call [viewController view];.

The documentation for UIViewController explains how the view property is lazy-loaded and that viewDidLoad is called after the view is loaded.