Interacting with View Controllers and Their Views

Let’s look at some methods that are called during the lifecycle of a view controller and its view. Some of these methods you have already seen, and some are new:

  • application:didFinishLaunchingWithOptions: is where you instantiate and set an application’s root view controller.

    This method gets called exactly once when the application has launched. Even if you go to another app and come back, this method does not get called again. If you reboot your phone and start the app again, application:didFinishLaunchingWithOptions: will get called again.

  • initWithNibName:bundle: is the designated initializer for UIViewController.

    When a view controller instance is created, its initWithNibName:bundle: gets called once. Note that in some apps, you may end up creating several instances of the same view controller class. This method will get called once on each as it is created.

  • loadView: is overridden to create a view controller’s view programmatically.

  • viewDidLoad can be overridden to configure views created by loading a NIB file. This method gets called after the view of a view controller is created.

  • viewWillAppear: can be overridden to configure views created by loading a NIB file.

    This method and viewDidAppear: will get called every time your view controller is moved on screen. viewWillDisappear: and viewDidDisappear: will get called every time your view controller is moved offscreen. So if you launch the app you are working on and hop back and forth between Hypnosis and Reminder, BNRReminderViewController’s viewDidLoad method will be called once, but viewWillAppear: will be called dozens of times.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset