A Cocoa Application: Views
Now that the model is taken care of, we turn to the other end of the application: the views. Our design for the application relies on standard elements in the Mac OS X Aqua interface.
Interface Builder (IB) is the indispensible tool for laying out human interfaces for Mac OS X applications. It edits Nib files, which are archives of human-interface objects that are reconstituted by your application when the files are loaded. All Cocoa application have a main Nib file, which the Xcode application template names Main-Menu.nib. This file contains at least the main menu bar for the application and may contain other applicationwide windows and views.
An application can have more than one Nib, and a Nib can be loaded and its contents instantiated more than once. For instance, the Xcode template for a document-based Cocoa application includes a MyDocument.nib file. The file contains a trivial window for documents of the MyDocument class, and the template for the MyDocument class implementation specifies MyDocument.nib as the Nib to load when creating a new document.
Because our design calls for a window that displays the data points and regression statistics for each document, we want to edit the window in MyDocument.nib to match our design. In the Groups & Files list, click the triangle next to Resources to open that group. You should see MyDocument.nib, with the gold icon of a Nib file, in that group. Double–clicking this item launches Interface Builder and opens MyDocument.nib for editing.
6.1 Interface Builder
The newly opened Interface Builder will show you three windows ( Figure 6.1). (Use Hide Others in the Interface Builder application menu to reduce the clutter.) The largest, named Window, contains a text element saying "Your document contents here" in the middle. Close this window.
Figure 6.1 Interface Builder on opening MyDocument.nib. The window that represents the Nib is at lower left; above it is the simple window, with some filler text, that comes in MyDocument.nib as provided in the template. To the right is the palette containing standard Aqua controls that can be dragged into windows.
The window at the lower left, MyDocument.nib, shows the Nib file as a file opened by Interface Builder (Figure 6.2). It shows three icons. The first two—File's Owner and First Responder—are placeholders for certain objects outside the Nib. Any other icons are for objects in the Nib—in this case, a window named Window.
Figure 6.2 The window for the MyDocument.nib file contains icons for File's Owner and First Responder, which are placeholders for objects outside the Nib, along with an icon for every top-level object in the Nib. In this case, MyDocument.nib contains only a window, named Window.
Double–click the Window icon. The window we're building for the MyDocument class opens again.
The third window, to the right, is a utility window embodying a series of palettes containing objects you can add to a Nib file. We'll be using this window a lot.