iOS View Controller Life Cycle
Page content
- Creation
- MVC are usually instantiated from Storyboards —- awakeFromNib() // this method is sent to all objects that come out of a storyboard. happens before outlets are set. happens before outlets are set.
- Outlet-setting
- ViewDidLoad()
override func viewDidLoad(){
super.viewDidLoad() // Important to call this
}
NOTE: Update your UI from your model as all the outlets are set at this stage. be careful that your geometry like what your bounds are not set. So do not do that.
- viewWillAppear()
- Your view will only get loaded only but will appear and disappear more than once. Maybe do some of the network calls in if you want to refresh some content. Also the GEOMETRY is set here, (like viewBounds etc).
- viewDidAppear()
- viewWillDisappear()
- cleanup code goes in here.
- viewDidDisappear()
Geometry Changes?
- Most of the time autolayout takes care of it
setNeedsDisplay ???
- viewWillLayoutSubviews() // setNeedsLayout will call this method.// maybe called multiple times.// maybe called before the viewDidAppear … Inbetween here Autolayout happens
- viewDidLayoutSubviews()
- Autorotation // Non-event in case of auto-layout.
- viewWillTransitionToSize()
- didReceiveMemoryWarning() Anything bit that is not in use should be released. // If its large image processing app then maybe
Summary: