Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
What Is a UIViewController?1:20 with Amit Bijlani
A UIViewController manages a set of views. It also provides lifecycle events while loading the views. These events can be captured to add custom code.
Now that we grasp the idea of a View, you're probably wondering what is a View Controller?
As the name suggests, a View Controller manages a set of Views and is an instance of the Class UIViewController.
Their job is to manage things like view resizing, layouts, reacting to interaction with views, handling events such as motion or touch,
and coordinating with data models or even other view controllers.
A View Controller also provides life-cycle events while it is loading and unloading Views.
If you want code to execute only once when the View has loaded, then use the method viewDidLoad.
If you want to allocate and initialize properties of instance variables then the viewDidLoad is a good place to do it.
Likewise, if you need to release memory or clear data then you can use the method viewDidUnload.
There are other methods like viewWillAppear or viewDidAppear
that are called each time the View Controller comes into view or disappears from view.
Then they will be ideal candidates to put some code that needs to be executed every time the view appears or disappears.
You need to sign up for Treehouse in order to download course files.Sign up