I've got a question regarding the two mentioned methods, since in my tests I don´t make clear the order they are called. I thought that, firstly, viewDidLoad
is called when the viewController is loaded for first time (as the name indicates), and inmediately after the init method. Then, I thought that once viewDidLoad
returns, viewWillAppear
is called. If you display another viewController, and then you return to this one, then it should be already loaded and only viewWillAppear
will be called.
However, while developing I make the impression that there is no order when calling viewDidLoad
and viewWillAppear
... I couldn´t find a clear description of this lifecycle in Apple's documentation, how does this actually work?
Thanks!
I would like to add to Caleb's answer: Don't confuse the view controller and the view! The name viewDidLoad
clearly indicates that the method is invoked after the view has been loaded. It is the view controller that does the loading.
Some pointers regarding the lifecycle of views and the order in which messages are sent:
UIViewController
's lifecycle overrides.loadView
and viewDidLoad
, also in conjunction with storyboards.viewWillAppear:
et al)I'm stopping here. You can find more stuff yourself by googling for "uiviewcontroller life cycle".