O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

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

Controls

The most visible aspects of an application are the controls that users interact with. In Cocoa, control objects such as buttons, tables, sliders, and text fields all have a common parent class: NSControl , which is itself a subclass of NSView. Figures Figure 3-6 and 3-7 show the class hierarchies for NSCell and NSControl, and Table 3-1 describes the control classes implemented in the Application Kit.

NSControl class hierarchy

Figure 3-6. NSControl class hierarchy

In general, a Cocoa control must have the ability to do several things:

  • Draw itself on the screen.

  • Respond to basic events such as a mouseclick or a drag.

  • Send action messages to arbitrary objects in response to events.

NSControl gives some amount of control over when and how a control sends the action message to its target. Specifically, you can specify whether the action is to be sent only after the user has finished clicking the control (i.e., when the mouse button is raised), or if the action is to be sent continuously while the mouse button is depressed. You can set this behavior either in Interface Builder or by using the method setContinuous:.

Cells

Most AppKit controls have associated cell classes, and in those cases the cell implements all drawing and event handling, while the control serves as a container within which the cell is drawn. A cursory comparison of NSCell to NSControl makes it appear as though these classes unnecessarily ...

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