Tuesday, March 24, 2015

Overview

The lifecycle for a ViewController is as follows.

Content

  1. Instantiated (from storyboard or code)
  2. awakeFromNib
  3. segue preparation happens
  4. outlets get set
  5. viewDidLoad
  6. viewWillAppear/viewDidAppaer and viewWillDisappear/viewDidDisappear
  7. viewWillLayoutSubviews


Lifecycle Methods

1
2
3
4
5
6
7
override func viewDidLoad() {
    // call super's version at beginning or end
    super.viewDidLoad()
    // do more setup
    // update your ui
    // geometry is not set yet (bounds)
}
1
2
3
4
5
func viewWillAppear(animated: Bool) {
    // every time the view gets displayed
    // geometry is set (bounds)
}
func viewDidAppear(animated: Bool)
1
2
3
4
5
6
override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    // clean up stuff
    // get rid of image
}
func viewDidDisappear(animated: Bool)
1
2
3
// your geometry has changed (rotate)
func viewWillLayoutSubviews()
func viewDidLayoutSubviews()

Random Posts