
uiviewcontroller_lifecycle
平時在講ViewController的生命周期時,我們只大多只關(guān)注以下六個方法:
-
viewDidLoad
*viewWillAppear viewDidAppearviewWillDisappearviewDidDisappearviewDidUnload
其實ViewController的生命周期如下:
-
loadView[1] -
viewDidLoad[1] viewWillAppear-
viewWillLayoutSubviews[2]Called to notify the view controller that its view is about to layout its subviews.
-
viewDidLayoutSubviews[2]
Called to notify the view controller that its view has just laid out its subviews.
viewDidAppearviewWillLayoutSubviewsviewDidLayoutSubviewsviewWillDisappearviewDidDisappearviewDidUnload
-
If you manually nil out your view during
didReceiveMemoryWarning,loadViewandviewDidLoadwill be called again. That is, by defaultloadViewandviewDidLoadonly gets called once per view controller instance. ? ? -
May be called an additional 0 or more times .
viewWillLayoutSubviewsandviewDidLayoutSubviewswill also be called at other times when subviews of the main view are loaded, for example when cells of a table view or collection view are loaded. ? ?