- Inherits from:
- NSCell : NSObject
- Conforms to:
- NSCoding
- (NSCell)
- NSCopying (NSCell)
- NSObject (NSObject)
Declared in:
- AppKit/NSActionCell.h
An NSActionCell defines an active area inside a control (an instance of NSControl or one of its subclasses). As an NSControl's active area, an NSActionCell does three things: it usually performs display of text or an icon; it provides the NSControl with a target and an action; and it handles mouse (cursor) tracking by properly highlighting its area and sending action messages to its target based on cursor movement.
NSActionCell implements the target object and action method as defined by its superclass, NSCell. As a user manipulates an NSControl, NSActionCell's trackMouse:inRect:ofView:untilMouseUp: method (inherited from NSCell) updates its appearance and sends the action message to the target object with the NSControl object as the only argument. See "Target and Action" below for more on this paradigm.
Usually, the responsibility for an NSControl's appearance and behavior is completely given over to a corresponding NSActionCell. (NSMatrix, and its subclass NSForm, are NSControls that don't follow this rule.)
A single NSControl may have more than one NSActionCell. To help identify it in this case, every NSActionCell has an integer tag. Note, however, that no checking is done by the NSActionCell object itself to ensure that the tag is unique. See the NSMatrix class for an example of a subclass of NSControl that contains multiple NSActionCells.
Many of the methods that define the contents and look of an NSActionCell, such as setFont: and setBordered:, are reimplementations of methods inherited from NSCell. They're overridden to ensure the NSActionCell is redisplayed when "visual" attributes change.
Target objects and action methods (or messages) are part of
the mechanism by which NSControls respond to user actions and enable
users to communicate their intentions to an application. A target
is an object an NSControl uses as the receiver of action messages.
The target's class defines an action method to enable its instances
to respond to these messages, which are sent as users click or otherwise manipulate
the NSControl. NSControl's sendAction:to: asks the NSApplication
object, NSApp
, to send
an action message to the NSControl's target object.
An action method takes only one argument: the id of the sender. The sender may be either the NSControl that sends the action message or, on occasion, another object that the target should treat as the sender. When it receives an action message, a target can return messages to the sender requesting additional information about its status.
You can also set the target to nil and allow it to be determined at run time. When the target is nil, the NSApplication object must look for an appropriate receiver. It conducts its search in a prescribed order, by following the responder chain until it finds an object that can respond to the message:
NSControl provides methods for setting and using the target object and the action method. However, these methods require that an NSControl's cell (or cells) be NSActionCells or custom cells that hold action and target as instance variables and can respond to the NSControl methods.
- Configuring an NSActionCell
- - setAlignment:
- - setBezeled:
- - setBordered:
- - setEnabled:
- - setFloatingPointFormat:left:right:
- - setFont:
- - setImage:
- Obtaining and setting cell values
- - doubleValue
- - floatValue
- - intValue
- - stringValue
- - setObjectValue:
- Displaying the NSActionCell
- - controlView
- Assigning target and action
- - setAction:
- - action
- - setTarget:
- - target
- Assigning a tag
- - setTag:
- - tag
- (SEL)action
See Also: - setAction:, - setTarget:, - target
- (NSView *)controlView
- (double)doubleValue
See Also: - validateEditing, - validateEditing (NSControl)
- (float)floatValue
See Also: - validateEditing (NSControl)
- (int)intValue
int
after
validating any editing of cell content. If the
receiver is not a text-type cell or the cell value is not scannable,
the method returns zero.See Also: - validateEditing (NSControl)
- (void)setAction:(SEL)aSelector
See Also: - action, - setTarget:, - target
- (void)setAlignment:(NSTextAlignment)mode
NSLeftTextAlignment
, NSRightTextAlignment
, NSCenterTextAlignment
, NSJustifiedTextAlignment
, NSNaturalTextAlignment
(the
default alignment for the text). The method marks the receiving NSActionCell
as needing redisplay after discarding any editing changes that were
being made to cell text.- (void)setBezeled:(BOOL)flag
- (void)setBordered:(BOOL)flag
- (void)setEnabled:(BOOL)flag
- (void)setFloatingPointFormat:(BOOL)autoRange
left:(unsigned int)leftDigits
right:(unsigned int)rightDigits
- (void)setFont:(NSFont
*)fontObj
- (void)setImage:(NSImage
*)image
- (void)setObjectValue:(id)object
- (void)setTag:(int)anInt
See Also: - tag
- (void)setTarget:(id)anObject
See Also: - action, - setAction:, - target
- (NSString *)stringValue
See Also: - validateEditing (NSControl)
- (int)tag
See Also: - setTag:
- (id)target
See Also: - action, - setAction:, - setTarget: