iOS View Controller Life Cycle

Page content
  1. Creation
  2. 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.
  3. Outlet-setting
  4. 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.

  1. 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).
  1. viewDidAppear()
  2. viewWillDisappear()
  • cleanup code goes in here.
  1. viewDidDisappear()

Geometry Changes?

  • Most of the time autolayout takes care of it setNeedsDisplay ???
  1. viewWillLayoutSubviews() // setNeedsLayout will call this method.// maybe called multiple times.// maybe called before the viewDidAppear … Inbetween here Autolayout happens
  2. viewDidLayoutSubviews()
  3. Autorotation // Non-event in case of auto-layout.
  4. viewWillTransitionToSize()
  5. didReceiveMemoryWarning() Anything bit that is not in use should be released. // If its large image processing app then maybe

Summary: