Mac Developer Library

Developer

AppKit Framework Reference NSTableColumn Class Reference

Options
Deployment Target:

On This Page
Language:

NSTableColumn

The NSTableColumn class stores the display characteristics and identifier for a column in an NSTableView instance. A table column object determines the width (including the maximum and minimum widths) of its column in the table view and specifies the column’s resizing and editing behavior.

A table column stores two cell objects: the header cell, which is used to draw the column header, and the data cell, which is used to draw the values for each row. In a cell-based table, you can control the display of the column by specifying subclasses of NSCell to use and by setting the font and other display characteristics for these cells. For example, you can use an NSTextFieldCell to display string values or substitute an NSImageCell to display pictures.

  • Initializes a newly created table column with a string identifier.

    Declaration

    Swift

    init(identifier identifier: String)

    Objective-C

    - (instancetype)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 set the table column title using the title property.

    This method is the designated initializer for the NSTableColumn class.

    Availability

    Available in OS X v10.0 and later.

    See Also

    identifier

  • The table view that contains the table column.

    Declaration

    Swift

    unowned(unsafe) var tableView: NSTableView?

    Objective-C

    @property(assign) NSTableView *tableView

    Discussion

    You should never need to set this property; it’s set 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

    addTableColumn: (NSTableView)

  • The table column’s width, in points.

    Declaration

    Swift

    var width: CGFloat

    Objective-C

    @property CGFloat width

    Discussion

    The default value of this property is 100.0.

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

    This property 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.

    See Also

    minWidth
    maxWidth

  • The table column’s minimum width, in points.

    Declaration

    Swift

    var minWidth: CGFloat

    Objective-C

    @property CGFloat minWidth

    Discussion

    The default value of this property is 10.0.

    The table column width can’t be less than the value of this property, whether the column is resized by the user or programmatically. If the table column’s current width is less than the value of this property, the width is set to the value of this property.

    Availability

    Available in OS X v10.0 and later.

    See Also

    maxWidth
    width

  • The table column’s maximum width, in points.

    Declaration

    Swift

    var maxWidth: CGFloat

    Objective-C

    @property CGFloat maxWidth

    Discussion

    The default value of this property is MAXFLOAT.

    The table column width can’t be greater than the value of this property, whether the column is resized by the user or programmatically. If the table column’s current width is greater than the value of this property, the width is set to the value of this property.

    Availability

    Available in OS X v10.0 and later.

    See Also

    minWidth
    width

  • The table column’s resizing mask.

    Declaration

    Swift

    var resizingMask: NSTableColumnResizingOptions

    Objective-C

    @property NSTableColumnResizingOptions resizingMask

    Discussion

    The value of this property specifies the resizability of the table column. See “Resizing Modes” for possible values. Values can be combined using the C bitwise OR operator.

    When the value of this property is 0, the column is not resizable. The default value of this property is NSTableColumnUserResizingMask | NSTableColumnAutoresizingMask.

    Availability

    Available in OS X v10.4 and later.

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

    Declaration

    Swift

    func sizeToFit()

    Objective-C

    - (void)sizeToFit

    Discussion

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

    If this method causes the table column’s width to change, the column’s table view is marked as needing display.

    Availability

    Available in OS X v10.0 and later.

  • The title of the table column’s header.

    Declaration

    Swift

    var title: String

    Objective-C

    @property(copy) NSString *title

    Availability

    Available in OS X v10.10 and later.

    See Also

    headerCell

  • The cell used to draw the table column’s header.

    Declaration

    Swift

    var headerCell: NSTableHeaderCell

    Objective-C

    @property(strong) __kindof NSTableHeaderCell *headerCell

    Discussion

    The value of this property must not be nil. It’s recommended that the value of this property be an instance or subclass of NSTableHeaderCell.

    You can set the table column title using the title property.

    Availability

    Available in OS X v10.0 and later.

    See Also

    title

  • The identifier string for the table column.

    Declaration

    Swift

    var identifier: String

    Objective-C

    @property(copy) NSString *identifier

    Discussion

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

    Availability

    Available in OS X v10.0 and later.

  • A Boolean that indicates whether a cell-based table’s column cells are user editable.

    Declaration

    Swift

    var editable: Bool

    Objective-C

    @property(getter=isEditable) BOOL editable

    Discussion

    When the value of this property is YEStrue, the user can edit cells in the cell-based table’s column. The default value of this property is YEStrue.

    To initiate editing programmatically regardless of the value of this property, use the NSTableView editColumn:row:withEvent:select: method.

    Availability

    Available in OS X v10.0 and later.

  • The table column’s sort descriptor prototype.

    Declaration

    Swift

    @NSCopying var sortDescriptorPrototype: NSSortDescriptor?

    Objective-C

    @property(copy) NSSortDescriptor *sortDescriptorPrototype

    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 that defines how to sort.

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether the table column is hidden.

    Declaration

    Swift

    var hidden: Bool

    Objective-C

    @property(getter=isHidden) BOOL hidden

    Discussion

    When the value of this property is YEStrue, the table column is hidden. The default value is NOfalse.

    Columns that are hidden still exist in the table view object’s tableColumns array and are included in the table view’s numberOfColumns count.

    The hidden state is stored when the table view autosaves the table column state.

    Availability

    Available in OS X v10.5 and later.

  • The string that’s displayed in a help tag over the table column header.

    Declaration

    Swift

    var headerToolTip: String?

    Objective-C

    @property(copy) NSString *headerToolTip

    Discussion

    When the value of this property is nil, the table column header doesn’t display a help tag (also known as a tooltip). Otherwise, the string is displayed in a help tag when the pointer pauses over the header of the table column. The default value of this property is nil.

    Availability

    Available in OS X v10.5 and later.

  • - isResizable (OS X v10.4)

    Returns whether the column is resizable.

    Deprecation Statement

    Use resizingMask instead.

    Declaration

    Objective-C

    - (BOOL)isResizable

    Return Value

    YEStrue if the user is allowed to resize the receiver in its NSTableView, NOfalse otherwise.

    Discussion

    You can change the table column size programmatically regardless of this setting, with the minimum and maximum constraints defined by minWidth and maxWidth.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

  • - setResizable: (OS X v10.4)

    Sets whether the user can resize the receiver in its NSTableView.

    Deprecation Statement

    Use resizingMask instead.

    Declaration

    Objective-C

    - (void)setResizable:(BOOL)flag

    Parameters

    flag

    YEStrue if the user can resize the table column; NOfalse otherwise.

    Discussion

    You can change the table column size programmatically regardless of this setting, with the minimum and maximum constraints defined by minWidth and maxWidth.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

  • dataCell dataCell (OS X v10.10) Property

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

    Deprecation Statement

    Cell-based table views are deprecated; use view-based table views instead. See tableView:viewForTableColumn:row: and viewAtColumn:row:makeIfNecessary:.

    Declaration

    Swift

    var dataCell: AnyObject

    Objective-C

    @property(strong) id dataCell

    Discussion

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

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

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

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

    Deprecation Statement

    Cell-based table views are deprecated; use view-based table views instead. See viewAtColumn:row:makeIfNecessary:.

    Declaration

    Swift

    func dataCellForRow(_ row: Int) -> AnyObject

    Objective-C

    - (id)dataCellForRow:(NSInteger)row

    Parameters

    row

    The table column row.

    Return Value

    The data cell object.

    Discussion

    Returns the NSCell object used by the table view to draw values for the receiver. The table view calls this method when drawing the row, so you shouldn’t need to call it directly. By default, this method just accesses dataCell.

    To enable per-row customization of the cell used by the table column, you can override this method or use the NSTableViewDelegate method tableView:dataCellForTableColumn:row:. In both cases, the cell that’s returned should properly implement copyWithZone:, because the table view may copy the cell during certain operations.

    Subclasses should be prepared for this method to be called with row equal to –1 in cases where no actual row is involved but the table view needs to get some generic cell information.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • These constants specify the resizing modes for a table column. The values are used to set the resizingMask property.

    Declaration

    Swift

    struct NSTableColumnResizingOptions : OptionSetType { init(rawValue rawValue: UInt) static var NoResizing: NSTableColumnResizingOptions { get } static var AutoresizingMask: NSTableColumnResizingOptions { get } static var UserResizingMask: NSTableColumnResizingOptions { get } }

    Objective-C

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

    Constants

    • NoResizing

      NSTableColumnNoResizing

      Prevents the table column from resizing.

      Available in OS X v10.4 and later.

    • AutoresizingMask

      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.

    • UserResizingMask

      NSTableColumnUserResizingMask

      Allows the table column to be resized by the user.

      Available in OS X v10.4 and later.