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)?
viewDidLoad method is called only once in ViewController lifecycle. The reason retrieveMessage() is called in viewDidLoad because it's adding observer to start listening for received and sent message.
viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.
viewDidLoad is the method that is called once the MainView of a ViewController has been loaded. This is called after loadView is called.In the image you can see the MainView and other views within it.
Use viewDidLoad( ), which is called AFTER loadView( ) has completed its job and the UIView is ready to be displayed. viewDidLoad( ) allows you to initialize properties of the view/viewController object and finalize them before viewWillAppear( ) is called.
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.
In iOS 9, Apple finally fixed this:
// Loads the view controller's view if it has not already been set. @available(iOS 9.0, *) public func loadViewIfNeeded()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With