Search code examples
iosiphoneviewdidloadloadview

Force viewDidLoad to fire on iOS


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)?


Solution

  • 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.