Learn Objective-C on the Mac - Mark Dalrymple [28]
It’s worth your time to spend a few minutes looking over the application delegate methods so you’ll know what’s there. The Documentation Browser is your friend. You’re going to spend a lot of time in here as you learn Cocoa, so get comfortable with it. If you’re running Snow Leopard, there’s also a more compact way to view documentation. Option-double-clicking on a class or method name will bring up a small documentation popup that gives you a brief summary of what you clicked on, and links to related documentation. Altogether, the documentation contained within Xcode is the ultimate encyclopedic reference to Cocoa, Xcode, and all other Apple development technologies. RTFM! You’ll be glad you did.
Figure 3-18. Xcode’s Documentation Browser can be brought up by option double-clicking an object, function, or method name in your source code. This is a fast and handy way to get to the documentation. This is yet another area where the GUI was reworked pretty drastically for Snow Leopard, but you should be able to find your way in either case.
Bring It on Home
The application you just built might not seem like much of an application, but the tasks you just executed to make it, such as declaring outlets and actions, designing your interface, connecting your outlets and actions, and writing action methods are some of the most fundamental building blocks of all Cocoa applications.
So, pat yourself on the back, grab a beverage of your choice, and turn the page when you’re ready to find out about the V in MVC as we take a look at several of Cocoa’s most common user interface elements, and see how to use them from your code.
Chapter 4
GUI Components
In Chapter 3, we covered some of the basics involved in creating a user interface in Interface Builder and using target/action to connect it to application code written in Xcode. We’ve really only scratched the surface so far, but you should be happy to know that the target/action system you learned to use in the last chapter is used by almost all of the user interface objects in Cocoa. If you’re not quite sure what’s so great about that, you might need to review Chapter 3 just one more time to be sure you’ve grasped the target/action concept.
By now, you’ve surely noticed the wide variety of user interface objects listed in Interface Builder’s Library window. Now it’s time to dig deeper into Cocoa’s bag of tricks, and explore some of these classes. The user interface classes available in Cocoa cover a wide range of uses, and wherever possible provide consistent APIs for their functionality, so that once you’ve learned how to do something with one class, you’ll often be able to quickly guess how to achieve similar results with another class.
In this chapter, we’ll cover some of the most common user interface classes that Cocoa provides, showing their basic usage and how you can tailor them to your needs where appropriate. Along the way, we’ll also touch on some of the auxiliary Cocoa classes that may not always have a tangible screen presence, but still provide important services for your applications. We’ll be focusing on the following classes (see Figure 4-1 for a sampling of what these objects can look like onscreen):■ NSTextField: The basic text input method for many applications. Responds to key-presses and renders text. Allows a great deal of editing flexibility for the user.
■ NSButton: The basic mouse-triggered GUI component. Despite their differences in operation and appearance, radio-buttons, checkboxes, and plain old buttons are all instances of NSButton.
■ NSPopUpButton: When you have a set of strings you want the user to choose from, an NSPopUpButton is often the way to go.
■ NSComboBox: Similar to an NSPopUpButton, but with the added advantage of allowing the user to enter a value that wasn’t already in the list.
■ NSMatrix: An NSMatrix lets you group a series of similar controls into a single unit.
■ NSLevelIndicator: Instances of this class are normally used for displaying a numeric value from a predefined range,