Xcode - View Controllers
MVC - Model View Controller
[Data] Model <--> [View] Controller <--> View
- Data Model - keeps the application's data
- View - displays the UI
- Contoller - Connects the Data Model to a View
iOS calls the UIViewController
methods as follows:
viewDidLoad()
- called when the view content is created and loaded from a storyboard. The view controller's outlets are guaranteed to have valid values when this is called. Use this method to perform any additional setup required by your view controllerviewWillAppear()
- called before the view content is created and loaded from a storyboard. Use this method to handle anything which needs to occur before the view is presented on screen. Note that the view might never become visible - it may be obsured by other views or hiddenviewDidAppear()
- called just after t view has been loaded. Use this method to handle anything which needs to occur as soon as the vie is presented on screen Note that the view might have never been visible - it may be obsured by other views or hiddenviewWillDisappear()
- called before the view content is about to be removed. Use this method to perform any cleanupviewDidDisappear()
- called just after the view conetent has been removed. Use this method to perform any cleanup. Note that the view might have never been visible - it may be obsured by other views or hidden
View Controllers
- Each screen in a storyboard typically has a its own View Controller
- View Controllers implement your app's behavior
- All View Controllers objects in iOS are of type of UIViewController
- Xcode created a UIViewController sub-class for you named ViewController in ViewController.swift