Class

NSControl

A definition of the fundamental behavior for controls, which are specialized views that notify your app of relevant events by using the target-action design pattern.

Declaration

@interface NSControl : NSView

Overview

The NSControl class is abstract and must be subclassed to be used. Although you can subclass it yourself, more often you use one of the subclasses already defined by AppKit. A control draws content on the screen, automatically handles user interactions with that content, and calls the action method of its target object for any significant user interactions.

About Delegate Methods

The NSControl class provides several delegate methods for its subclasses that allow text editing, such as NSTextField and NSMatrix. These include: controlTextDidBeginEditing:, controlTextDidChange:, and controlTextDidEndEditing:.

Note that although NSControl defines delegate methods, it does not itself have a delegate. Any subclass that uses these methods must have a delegate and the methods to get and set it. In addition, a formal delegate protocol NSControlTextEditingDelegate also defines delegate methods used by control delegates.

Topics

Creating a Control

- initWithFrame:

Returns an NSControl object initialized with the specified frame rectangle.

Accessing the Control’s Cell

cellClass

Returns the type of cell used by the receiver.

Deprecated

Enabling and Disabling the Control

enabled

A Boolean value that indicates whether the receiver reacts to mouse events.

Accessing the Control’s Value

doubleValue

The value of the receiver’s cell as a double-precision floating-point number.

floatValue

The value of the receiver’s cell as a single-precision floating-point number.

intValue

The value of the receiver’s cell as an integer.

integerValue

The value of the receiver’s cell as an NSInteger value.

objectValue

The value of the receiver’s cell as an Objective-C object.

stringValue

The value of the receiver’s cell as an NSString object.

attributedStringValue

The value of the receiver’s cell as an attributed string.

Interacting with Other Controls

- takeDoubleValueFrom:

Sets the value of the receiver’s cell to a double-precision floating-point value obtained from the specified object.

- takeFloatValueFrom:

Sets the value of the receiver’s cell to a single-precision floating-point value obtained from the specified object.

- takeIntValueFrom:

Sets the value of the receiver’s cell to an integer value obtained from the specified object.

- takeIntegerValueFrom:

Sets the value of the receiver’s cell to an NSInteger value obtained from the specified object.

- takeObjectValueFrom:

Sets the value of the receiver’s cell to the object value obtained from the specified object.

- takeStringValueFrom:

Sets the value of the receiver’s cell to the string value obtained from the specified object.

Formatting Text

alignment

The alignment mode of the text in the receiver’s cell.

font

The font used to draw text in the receiver’s cell.

lineBreakMode

The line break mode to use for text in the control’s cell.

usesSingleLineMode

A Boolean value that indicates whether the text in the control’s cell uses single line mode.

- setFloatingPointFormat:left:right:

Sets the auto-ranging and floating point number format of the receiver’s cell.

Deprecated
formatter

The receiver’s formatter.

baseWritingDirection

The initial writing direction used to determine the actual writing direction for text.

Managing Expansion Tool Tips

- drawWithExpansionFrame:inView:

Performs custom expansion tool tip drawing.

allowsExpansionToolTips

A Boolean value that indicates whether expansion tool tips are shown when the control is hovered over.

- expansionFrameWithFrame:

The frame in which a tool tip can be displayed, if needed.

Managing the Field Editor

- abortEditing

Terminates the current editing operation and discards any edited text.

- currentEditor

Returns the current field editor for the control.

- validateEditing

Validates changes to any user-typed text.

- editWithFrame:editor:delegate:event:

Begins editing of the receiver’s text using the specified field editor.

- endEditing:

Ends the editing of text in the receiver using the specified field editor.

- selectWithFrame:editor:delegate:start:length:

Selects the specified text range in the receiver's field editor.

Resizing the Control

controlSize

The size of the control.

NSControlSize

Constants for specifying a cell’s size.

- sizeThatFits:

Asks the control to calculate and return the size that best fits the specified size.

- sizeToFit

Resizes the receiver’s frame so that it is the minimum size needed to contain its cell.

Displaying a Cell

highlighted

A Boolean value that indicates whether the cell is highlighted.

Implementing the Target/Action Mechanism

action

The default action-message selector associated with the control.

target

The target object that receives action messages from the cell.

continuous

A Boolean value indicating whether the receiver’s cell sends its action message continuously to its target during mouse tracking.

- sendAction:to:

Causes the specified action to be sent the target.

- sendActionOn:

Sets the conditions on which the receiver sends action messages to its target.

Accessing Tags

tag

The tag identifying the receiver (not the tag of the receiver’s cell).

Activating from the Keyboard

- performClick:

Simulates a single mouse click on the receiver.

refusesFirstResponder

A Boolean value indicating whether the receiver refuses the first responder role.

Tracking the Mouse

- mouseDown:

Informs the receiver that the user has pressed the left mouse button.

ignoresMultiClick

A Boolean value indicating whether the receiver ignores multiple clicks made in rapid succession.

Control Editing Notifications

- controlTextDidBeginEditing:

Sent when a control with editable text begins an editing session.

Deprecated
- controlTextDidChange:

Sent when the text in the receiving control changes.

Deprecated
- controlTextDidEndEditing:

Sent when a control with editable text ends an editing session.

Deprecated

Supporting Constraint-Based Layout

- invalidateIntrinsicContentSizeForCell:

Notifies the control that the intrinsic content size for its cell is no longer valid.

Notifications

An NSControl object posts the following notifications to interested observers and its delegate. Note that although the NSControl class defines delegate methods, it does not itself have a delegate. Any subclass that uses these methods must have a delegate and the methods to get and set it.

NSControlTextDidBeginEditingNotification

Sent when a control with editable cells begins an edit session.

NSControlTextDidChangeNotification

Sent when the text in the receiving control changes.

NSControlTextDidEndEditingNotification

Sent when a control with editable cells ends an editing session.

Deprecated

cell

The receiver’s cell object.

Deprecated
- selectedCell

Returns the receiver’s selected cell.

Deprecated
- selectedTag

Returns the tag of the receiver’s selected cell.

Deprecated
- setNeedsDisplay

Marks the receiver as needing redisplay (assuming automatic display is enabled).

Deprecated
- calcSize

Recomputes any internal sizing information for the receiver, if necessary.

Deprecated
- selectCell:

Selects the specified cell and redraws the control as needed.

Deprecated
- drawCell:

Draws the specified cell, as long as it belongs to the receiver.

Deprecated
- drawCellInside:

Draws the inside of the receiver’s cell (the area within the bezel or border)

Deprecated
- updateCell:

Marks the specified cell as in need of redrawing.

Deprecated
- updateCellInside:

Marks the inside of the specified cell as in need of redrawing.

Deprecated

Relationships

Inherits From

See Also

View Fundamentals

NSView

The infrastructure for drawing, printing, and handling events in an app.

NSCell

A mechanism for displaying text or images in a view object without the overhead of a full NSView subclass.

NSActionCell

An active area inside a control.