NSTableColumn Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSTableColumn.h
Related sample code

Overview

The NSTableColumn class stores the display characteristics and attribute identifier for a column in an NSTableView instance. The table column determines the width and width limits, resizing and editing of its column in the table view.

Table columns also store two NSCell objects: the header cell, which is used to draw the column header, and the data cell, used to draw the values for each row. You can control the display of the column by setting the subclasses of NSCell used and by setting the font and other display characteristics for these cells. For example, you can use an NSTextFieldCell for displaying string values or substitute an NSImageCell to display pictures.

Tasks

Creating an NSTableColumn

Setting the NSTableView

Controlling Size

Setting Component Cells

Setting the Identifier

Controlling Editability

Sorting

Setting Column Visibility

Setting Tool Tips

Deprecated Methods

Instance Methods

dataCell

Returns the cell prototype object used to draw individual cells.

- (id)dataCell
Return Value

The NSCell subclass used as the prototype for table column cells.

Discussion

When using a cell-based table view with Cocoa bindings the bindings infrastructure may directly call this method to access bindings and properties set on the cell.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

dataCellForRow:

Returns the cell instance used to display values in the specified row of the table column.

- (id)dataCellForRow:(NSInteger)row
Parameters
row

The table column row.

Return Value

The data cell instance.

Discussion

NSTableView always calls this method. By default, this method just calls dataCell.

Subclassers can override this method if they need to use different cell types for different rows in a column. Subclasses should expect this method to be invoked with row equal to –1 in cases where no actual row is involved but the table view needs to get some generic cell info.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

headerCell

Returns the cell used to draw the table column’s header.

- (id)headerCell
Return Value

The header cell

Discussion

You can set the table column title by sending setStringValue: to this object.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

headerToolTip

Returns the tooltip string that is displayed when the cursor hovers over the header cell.

- (NSString *)headerToolTip
Return Value

The tooltip displayed when the cursor pauses over the header cell of the receiver.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTableColumn.h

identifier

Returns the identifier string.

- (NSString *)identifier
Return Value

The table column identifier string.

Discussion

This string is used by the data source to identify the attribute corresponding to the table column.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

initWithIdentifier:

Initializes a newly created table column with a string identifier.

- (id)initWithIdentifier:(NSString *)identifier
Parameters
identifier

The string identifier for the column.

Return Value

An initialized table column instance with an NSTextFieldCell instance as its default cell.

Discussion

You can send the setStringValue: message to the column’s headerCell to set the column title.

This method is the designated initializer for the NSTableColumn class.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

isEditable

Returns whether the table column cells are user editable.

- (BOOL)isEditable
Return Value

YES if the user can edit cells by double-clicking the cell in the table column; NO otherwise.

Discussion

You can initiate editing programmatically regardless of this setting with NSTableView’s editColumn:row:withEvent:select: method.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

isHidden

Returns whether the table column is hidden.

- (BOOL)isHidden
Return Value

YES if the table column is hidden; NO otherwise.

Discussion

The hidden state of the receiver is stored when the tableview autosaves the table column state.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTableColumn.h

maxWidth

Returns the maximum width of the table column.

- (CGFloat)maxWidth
Return Value

The maximum width of the table column, in points.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

minWidth

Returns the table column’s minimum width.

- (CGFloat)minWidth
Return Value

The table column width, in points.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

resizingMask

Returns the table column’s resizing mask.

- (NSUInteger)resizingMask
Return Value

Returns the resizing mask.

Discussion

See “Resizing Modes” for a description of the resizing mask constants.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSTableColumn.h

setDataCell:

Sets the cell prototype used by the table column to draw individual cells.

- (void)setDataCell:(NSCell *)aCell
Parameters
aCell

A cell to use as the data cell.

Discussion

You can use this method to control the font, alignment, and other text attributes for the table column.

You can also assign a cell to display things other than text—for example, an to display images by setting the cell to NSImageCell.

Availability
  • Available in OS X v10.0 and later.
See Also
Related Sample Code
Declared In
NSTableColumn.h

setEditable:

Sets whether the user can edit cells in the table column.

- (void)setEditable:(BOOL)flag
Parameters
flag

YES if a double click initiates editing; if NO the double-click action to the table view’s target.

Discussion

You can initiate editing programmatically regardless of this setting using the NSTableView editColumn:row:withEvent:select: method.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

setHeaderCell:

Sets the cell used to draw the table columns header.

- (void)setHeaderCell:(NSCell *)aCell
Parameters
aCell

The cell to use as the table column header. This value must not be nil.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

setHeaderToolTip:

Sets the tooltip string that is displayed when the cursor hovers over the header cell.

- (void)setHeaderToolTip:(NSString *)string
Parameters
string

A string that functions as the tooltip for the header cell of the receiver.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSTableColumn.h

setHidden:

Sets whether the table column is hidden.

- (void)setHidden:(BOOL)aFlag
Parameters
aFlag

YES if the receiver is to be hidden; NO otherwise.

Discussion

Columns which are hidden still exist in the NSTableView instance’s tableColumns array and are included in the NSTableView instance’s numberOfColumns count.

The hidden state of the receiver is stored when the tableview autosaves the table column state.

Availability
  • Available in OS X v10.5 and later.
See Also
Declared In
NSTableColumn.h

setIdentifier:

Sets the table column’s identifier to the specified string..

- (void)setIdentifier:(NSString *)aString
Parameters
aString

The column identifier string.

Discussion

This string is used by the data source to identify the attribute corresponding to the table column.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

setMaxWidth:

Sets the table column’s maximum width

- (void)setMaxWidth:(CGFloat)maxWidth
Parameters
maxWidth

The maximum table column width, in points.

Discussion

If the table column’s current width is greater than maxWidth, the width is set to the maxWidth value.

The table column width can’t be greater than this value, whether dragged by the user or being set programmatically.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

setMinWidth:

Sets the table column’s minimum width.

- (void)setMinWidth:(CGFloat)minWidth
Parameters
minWidth

The minimum table column width, in points.

Discussion

If the table column’s current width is less than minWidth, the width is set to the minWidth value.

The table column width can’t be less than this value, whether dragged by the user or being set programmatically.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

setResizingMask:

Sets the resizing mask for the table column.

- (void)setResizingMask:(NSUInteger)resizingMask
Parameters
resizingMask

The resizing mask. See “Resizing Modes” for the possible values. Values can be combined using the C bitwise OR operator. If resizingMask is 0, the column is not resizable.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSTableColumn.h

setSortDescriptorPrototype:

Sets the table column sort descriptor prototype.

- (void)setSortDescriptorPrototype:(NSSortDescriptor *)sortDescriptor
Parameters
sortDescriptor

The sort descriptor prototype.

Discussion

A table column is considered sortable if it has a sort descriptor that specifies the sorting direction, a key to sort by, and a selector defining how to sort.

Availability
  • Available in OS X v10.3 and later.
Declared In
NSTableColumn.h

setTableView:

Sets the table view that contains the table column.

- (void)setTableView:(NSTableView *)aTableView
Parameters
aTableView

The table view.

Discussion

You should never need to invoke this method; it’s invoked automatically when you add a table column to a table view using the NSTableView class’s method addTableColumn:.

Availability
  • Available in OS X v10.0 and later.
See Also
Declared In
NSTableColumn.h

setWidth:

Sets the table column’s width to the specified value.

- (void)setWidth:(CGFloat)newWidth
Parameters
newWidth

The new column width, in points.

Discussion

If newWidth exceeds the minimum or maximum width, it’s adjusted to the appropriate limiting value.

This method posts NSTableViewColumnDidResizeNotification on behalf of the table column’s NSTableView and marks the table view as needing display.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

sizeToFit

Resizes the table column to fit the width of its header cell.

- (void)sizeToFit
Discussion

If the maximum width is less than the width of the header, the maximum is increased to the header’s width. Similarly, if the minimum width is greater than the width of the header, the minimum is reduced to the header’s width.

Marks the NSTableView instance containing the table column’s as needing display if the width actually changes.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

sortDescriptorPrototype

Returns the table column’s sort descriptor prototype.

- (NSSortDescriptor *)sortDescriptorPrototype
Return Value

The sort descriptor prototype.

Availability
  • Available in OS X v10.3 and later.
Declared In
NSTableColumn.h

tableView

Returns the NSTableView the receiver belongs to.

- (NSTableView *)tableView
Return Value

The NSTableView instance that contains the table column.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

width

Returns the table column’s width.

- (CGFloat)width
Return Value

The width of the table column, in points.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSTableColumn.h

Constants

Resizing Modes

These constants specify the resizing modes for a table column. These values are then passed as the parameter to the setResizingMask: method.

enum {
   NSTableColumnNoResizing = 0,
   NSTableColumnAutoresizingMask = ( 1 << 0 ),
   NSTableColumnUserResizingMask = ( 1 << 1 )
};
Constants
NSTableColumnNoResizing

Prevents the table column from resizing.

Available in OS X v10.4 and later.

Declared in NSTableColumn.h.

NSTableColumnAutoresizingMask

Allows the table column to resize automatically in response to resizing the table view. The resizing behavior for the table view is set using the NSTableView method setColumnAutoresizingStyle:.

Available in OS X v10.4 and later.

Declared in NSTableColumn.h.

NSTableColumnUserResizingMask

Allows the table column to be resized explicitly by the user.

Available in OS X v10.4 and later.

Declared in NSTableColumn.h.


Did this document help you? Yes It's good, but... Not helpful...