Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights Reserved.


Inherits From: NSObject

Conforms To: NSCoding, NSCopying NSObject (NSObject)

Declared In: AppKit/NSCell.h

Class Description

The NSCell class provides a mechanism for displaying text or images in an NSView without the overhead of a full NSView subclass. In particular, it provides much of the functionality of the NSText class by providing access to a shared NSText object used by all instances of NSCell in an application. NSCells are also extremely useful for placing titles or images at various locations in a custom subclass of NSView.

NSCell is used heavily by most of the NSControl classes to implement their internal workings. For example, NSSlider uses an NSSliderCell, NSTextField uses an NSTextFieldCell, and NSBrowser uses an NSBrowserCell. Sending a message to the NSControl is often simpler than dealing directly with the corresponding NSCell. For instance, NSControls typically invoke updateCell: (causing the cell to be displayed) after changing a cell attribute; whereas if you directly call the corresponding method of the NSCell, the NSCell might not automatically display itself again.

Some subclasses of NSControl (notably NSMatrix) allow multiple NSCells to be grouped and to act together in some cooperative manner. Thus, with an NSMatrix, a group of radio buttons can be implemented without needing an NSView for each button (and without needing an NSText object for the text on each button).

The NSCell class provides primitives for displaying text or an image, editing text, formatting floating-point numbers, maintaining state, highlighting, and tracking the mouse. NSCell's method trackMouse:inRect:ofView:untilMouseUp: supports the target object and action method used to implement controls. However, NSCell implements target/action features abstractly, deferring the details of implementation to subclasses of NSActionCell.

The initImageCell: method is the designated initializer for NSCells that display images. The initTextCell: method is the designated initializer for NSCells that display text. Override one or both of these methods if you implement a subclass of NSCell that performs its own initialization. If you need to use target and action behavior, you may prefer to subclass NSActionCell, which provides the default implementation of this behavior.

For more information on how NSCell is used, see the NSControl class specification.

Initializing an NSCell

Determining Component Sizes

Setting the NSCell's Type

Setting the NSCell's State

Enabling and Disabling the NSCell

Setting the Image

Setting the NSCell's Value

Interacting with Other NSCells

Modifying Text Attributes

Editing Text

Formatting Data

Setting Parameters


Target and Action

Assigning a Tag

Handling Keyboard Alternatives

Tracking the Mouse

Managing the Cursor

Using the NSCell to Represent an Object