Managing Multiple Nibs

When a Cocoa application starts up, all of the objects stored in its main nib are loaded into memory and initialized. This takes time (the more objects, the more time), and until the nib is loaded, your application can’t do anything else. This can be real drag, especially if your program doesn’t need most of the objects in the main nib for normal operation. For this reason, Cocoa lets you take objects that you don’t use often and place them in separate nibs. You can arrange for these auxiliary nibs to be loaded only when they are needed.

Auxiliary nibs should be used for most panels that do not need to be displayed when your program first starts up. Instead, the files are loaded the first time that the panel is needed. Once the panel is loaded, it is resident in your computer’s memory — additional attempts to make the panel display go much faster.

Now we’ll arrange for our Calculator application to use a separate nib for its About box. This will consist of three steps:

  1. Creating the new nib that contains the About box

  2. Modifying the Controller class to load this new nib (and thereby display the About box)

  3. Modifying the Calculator’s MainMenu.nib accordingly

For pedagogical reasons, we’ll perform these steps in the order (ii), then (iii), and finally (i).

Modifying the Controller Class

To start, we’ll modify the Controller object to add two things:

aboutPanel

A new outlet that holds the id of the About box

showAboutPanel:

A new action method that displays the ...

Get Building Cocoa Applications: A Step by Step Guide 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.