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.
![]() |
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
