The View Controller Lifecycle and Low-Memory Warnings

A view controller, like any other object, is created through alloc and init. It does not, however, create its view at that time. Instead, it waits until the view is really needed before it calls loadView. This lazy creation of the view is good: for example, if you have a tab view with a dozen view controllers, the view for any particular view controller will only be created if that particular tab is selected. You can see this behavior in the console when you build and run HypnoTime – you will only see the log message indicating that the CurrentTimeViewController’s view is loaded after you switch to the Time tab for the first time.

How does a view controller know when to load its view? When ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.