Life of viewcontroller

#objective c#ios#novice

life of view controllers


life of view controller

  • init: ViewController loaded, no interface element (IBOutlet) available yet (all nil)
  • viewDidLoad: the nib/storyboard has been loaded and all objects are available. The user sees nothing yet not sure of the Geometry of the Device
  • viewWillAppear: the view is about to be displayed
  • viewDidAppear: the view is on screen
  • viewWillDisappear: the view is about to go away
  • viewDidDisappear: the view just was taken off the window
  • viewDidUnload: NEVER CALLED in iOS6/7
  • didReceiveMemoryWarning: You don’t know if, when and how often this is called. Prior to iOS6 it might unload the view, after iOS6 it just purges an offscreen cache or does nothing
  • dealloc: the viewController is about to get destroyed

usage of view controller

  • viewDidLoad: Add Observers for non-view things. Override this method to perform additional initialization on views that were loaded from nib files. Called when you create the class and load from xib.

  • viewWillAppear: Adjust Geometry of the Device add Observers for UI effects. good for hiding/showing fields or any operations that you want to happen every time before the view is visible Called after the view appears - great place to start an animations or the loading of external data from an API.

  • viewDidAppear: start an animations or the loading of external data from an API. Add observers for external data UI effects.

  • viewWillDisappear: remove observers for UI effects

  • viewDidDisappear: remove observers for external data UI effects

  • dealloc remove Observers for non-view things.

« Quote post