O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nib Loading and File’s Owner

A nib file is useless until your app runs and the nib file is loaded. One nib, designated by the Info.plist key “Main nib file base name” (NSMainNibFile, see Chapter 6), is loaded automatically as the app launches. Other nibs are loaded explicitly as needed while the app runs.

For example, imagine our app has two complete sets of interface, and the user might never ask to see the second one. It makes obvious sense not to load a nib containing the second set of interface until the user does ask to see it. By this strategy, a nib is loaded when its instances are needed, and those instances are destroyed when they are no longer needed. Thus memory usage is kept to a minimum, which is important because memory is at a premium in a mobile device. Also, loading a nib takes time, so loading fewer nibs at launch time makes launching faster.

When a nib loads, some already existing instance is designated its owner. A nib cannot load without an owner, and the owner must exist before the nib can load.

In the case of the automatically loaded main nib file, the owner is the single UIApplication instance created automatically as the app launches (the shared application object). In other cases, the nib’s owner must be specified in order to load the nib. It will often be a UIViewController instance, because a UIViewController already knows how to load a nib and manage a view that it contains (Chapter 19), but it can be an instance of any class.

The File’s Owner top-level ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required