Learn Objective-C on the Mac - Mark Dalrymple [8]
NOTE: If you close the library, you can open it again by selecting Library from the Tools menu or by typing ⌘L.
The library is divided into three primary panes, as shown in Figure 2-5. The top pane is called the organization pane, and lets you select specific groups of objects you’d like to explore. The middle pane is called the item pane. Obviously, the selection in the organization pane determines which items are displayed in the item pane. Finally, the bottom pane is called the detail pane. As its name suggests, the detail pane shows details about the currently selected item in the item pane.
Figure 2-5. The parts of Interface Builder’s library
Single-click the disclosure triangle next to the word Library in the organization pane (the top part of the library window), which should reveal a number of additional categories. The first one below Library should be called Cocoa, and it should also have a disclosure triangle next to it also. Click that one as well.
There are three sub-items under Cocoa. The first one is called Application, and contains objects that apply to your whole application, such as menus and windows. We already have all the menus and windows we need for now, so we can skip that one for the time being.
The second item is called Objects & Controllers. These are things that will help you manage your application data, but because we don’t have any application data in this chapter, we’re going to skip over this one for now, too. Don’t worry, we’ll return to these in later chapters.
The final sub-item under Cocoa is called Views & Cells. These are the various views and controls that can be used to build your application’s user interface. Expand Views & Cells, and single-click the sub-item named Inputs & Values (Figure 2-6).
Figure 2-6. The Library with the Label selected
Dragging Out a Label
The library’s item pane will show a list of items that can be dragged to your application window to build your application’s interface. Let’s drag one over now. The first item under Inputs & Values is called Label, and is used to display static text, text that the user can’t edit. Let’s drag a label over to the Window window.
In the library window, click on the first row in the item pane and drag a Label over to your application’s main window (the window labeled Window). If you accidentally close your application window, you can bring it back up by double-clicking the icon labeled Window in the nib file’s main window (the window labeled MainMenu.xib). Doing this will add a new label to your application’s window.
TIP: Instead of drilling down through the hierarchy as we just did, we could have just typed the word “label” into the search field at the bottom of the library window. This would have filtered down the list to show only those objects in the library with the word “label” in their name or description.
Now that you’ve got a label, let’s change it. Double-click the label. It should become editable and selected (Figure 2-7).
Figure 2-7. The new label becomes editable when double-clicked.
Because the existing text is selected, you can just type your new text and it will replace what was there before. Go ahead and type “Hello, World!”, which is infinitely less boring than “Label.” If you’re feeling rebellious, you could type something else, but don’t blame us if the Tiki Gods come after you!
Using the Blue Guidelines
When you’re done editing the label, press return to commit the changes, which will take that label out of editing mode.