Mobile Development

View Controllers

Apple includes a variety of View Controllers which organize your views and provide a controller class for delegates and other interactions.

UIViewController

UIViewController is the building block for user interfaces. You will typically subclass UIViewController in the development of your own view controllers.

The UIViewController class provides the fundamental view-management model for all iOS apps

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html

View Controller Life Cycle

UIViewController provides a number of methods that you can override at various points of the view controller's life cycle.

Source: http://rdkw.wordpress.com/2013/02/24/ios-uiviewcontroller-lifecycle/

Common methods to overide

Depending on what you want to accomplish, the following methods can be overridden. These are all optional overrides.

Method name Common Use Case
viewDidLoad: One-time setup, called when app has already loaded the XIB but has not started to display
viewWillAppear: Called each time the view will begin to appear on screen. Setup data on screen such as labels.
viewDidAppear: Called when the view has completed being displayed to the user. Use for custom animations on hidden views.
viewWillDisappear: Called each time the view is about to begin disappearing. Use for more custom animations and for saving data to disk.
viewDidDisappear: View has disappeared and view controller may be removed from memory.
didReceiveMemoryWarning iOS will begin trying to reclaim memory. Release memory that can be recreated easily.

Derivatives

UIViewController is used as the base class for other common view controllers including UITableViewController and UICollectionViewController. These two additional classes will include other protocols that will need to be defined within the implementation.

UITableViewController

The UITableViewController class creates a controller object that manages a table view.

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableViewController_Class/index.html

UICollectionViewController

The UICollectionViewController class represents a view controller whose content consists of a collection view

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionViewController_clas/index.html

References

Apple UIKit Reference https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKit_Framework/

View Controller Programming Guide https://developer.apple.com/library/prerelease/tvos/featuredarticles/ViewControllerPGforiPhoneOS/index.html