Mac Developer Library

Developer

AppKit Framework Reference NSTableColumn Class Reference

Options
Deployment Target:

On This Page
Language:

NSTableColumn

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

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

    To set the column title in a cell-based table, you can call setStringValue: on the column’s headerCell.

    This method is the designated initializer for the NSTableColumn class.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the table view that contains the table column.

    Declaration

    Swift

    unowned(unsafe) var tableView: NSTableView?

    Objective-C

    @property(assign) NSTableView *tableView

    Parameters

    aTableView

    The table view.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – tableView
    addTableColumn: (NSTableView)

  • Returns the table view that the column belongs to.

    Declaration

    Swift

    unowned(unsafe) var tableView: NSTableView?

    Objective-C

    @property(assign) NSTableView *tableView

    Return Value

    The NSTableView instance that contains the table column.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var width: CGFloat

    Objective-C

    @property CGFloat width

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the table column’s width.

    Declaration

    Swift

    var width: CGFloat

    Objective-C

    @property CGFloat width

    Return Value

    The width of the table column, in points. The default value is 100.0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the table column’s minimum width.

    Declaration

    Swift

    var minWidth: CGFloat

    Objective-C

    @property 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 minWidth, whether the column is resized by the user or programmatically.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the table column’s minimum width.

    Declaration

    Swift

    var minWidth: CGFloat

    Objective-C

    @property CGFloat minWidth

    Return Value

    The minimum width of the table column, in points. The default value is 10.0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the table column’s maximum width.

    Declaration

    Swift

    var maxWidth: CGFloat

    Objective-C

    @property CGFloat maxWidth

    Parameters

    maxWidth

    The maximum width of the table column, 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 maxWidth, whether the column is resized by the user or programmatically.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the table column’s maximum width.

    Declaration

    Swift

    var maxWidth: CGFloat

    Objective-C

    @property CGFloat maxWidth

    Return Value

    The maximum width of the table column, in points. The default value is MAXFLOAT.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the table column’s resizability.

    Declaration

    Swift

    var resizingMask: NSTableColumnResizingOptions

    Objective-C

    @property NSTableColumnResizingOptions resizingMask

    Parameters

    resizingMask

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Returns the table column’s resizing mask.

    Declaration

    Swift

    var resizingMask: NSTableColumnResizingOptions

    Objective-C

    @property NSTableColumnResizingOptions resizingMask

    Return Value

    Returns the resizing mask that specifies the table column’s resizability. The default value is NSTableColumnUserResizingMask | NSTableColumnAutoresizingMask.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var headerCell: AnyObject

    Objective-C

    @property(strong) id headerCell

    Parameters

    aCell

    The cell to use as the table column header. This value must not be nil. It’s recommended that aCell be an instance or subclass of NSTableHeaderCell.

    Discussion

    This method is only valid for cell-based table views.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – headerCell

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

    Declaration

    Swift

    var headerCell: AnyObject

    Objective-C

    @property(strong) id headerCell

    Return Value

    The header cell.

    Discussion

    You can set the table column title by calling setStringValue: on headerCell.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    var dataCell: AnyObject

    Objective-C

    @property(strong) id dataCell

    Parameters

    aCell

    A cell to use as the cell prototype.

    Discussion

    You can use this method 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

    See Also

    – dataCell

  • dataCell - dataCell (OS X v10.10)

    Returns the cell prototype object used to draw individual cells.

    Declaration

    Swift

    var dataCell: AnyObject

    Objective-C

    @property(strong) 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    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 calls 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

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

    Declaration

    Swift

    var identifier: String!

    Objective-C

    @property(copy) NSString *identifier

    Parameters

    aString

    The column identifier string.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – identifier

  • Returns the identifier string.

    Declaration

    Swift

    var identifier: String!

    Objective-C

    @property(copy) NSString *identifier

    Return Value

    The table column identifier string.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets whether the user can edit cells in a cell-based table’s column.

    Declaration

    Swift

    var editable: Bool

    Objective-C

    @property(getter=isEditable) BOOL editable

    Parameters

    flag

    YEStrue if the cell in the table column of a cell-based table view is editable, NOfalse if the cell is not editable.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – isEditable

  • isEditable - isEditable Available in OS X v10.0 through OS X v10.9

    Returns whether a cell-based table’s column cells are user editable.

    Declaration

    Objective-C

    - (BOOL)isEditable

    Return Value

    YEStrue if the user can edit cells in the cell-based table’s column; NOfalse otherwise. The default value is YEStrue.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Sets the table column’s sort descriptor prototype.

    Declaration

    Swift

    @NSCopying var sortDescriptorPrototype: NSSortDescriptor?

    Objective-C

    @property(copy) NSSortDescriptor *sortDescriptorPrototype

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the table column’s sort descriptor prototype.

    Declaration

    Swift

    @NSCopying var sortDescriptorPrototype: NSSortDescriptor?

    Objective-C

    @property(copy) NSSortDescriptor *sortDescriptorPrototype

    Return Value

    The sort descriptor prototype.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • isHidden - isHidden Available in OS X v10.5 through OS X v10.9

    Returns whether the table column is hidden.

    Declaration

    Objective-C

    - (BOOL)isHidden

    Return Value

    YEStrue if the table column is hidden; NOfalse otherwise. The default value is NOfalse.

    Discussion

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

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.5 through OS X v10.9.

    See Also

    – setHidden:

  • Sets whether the table column is hidden.

    Declaration

    Swift

    var hidden: Bool

    Objective-C

    @property(getter=isHidden) BOOL hidden

    Parameters

    aFlag

    YEStrue if the table column is to be hidden; NOfalse otherwise.

    Discussion

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – isHidden

  • Sets the string that’s displayed in a help tag.

    Declaration

    Swift

    var headerToolTip: String?

    Objective-C

    @property(copy) NSString *headerToolTip

    Parameters

    string

    A string that contains the text to display in a help tag (also known as a tooltip). If no string is set, the table column header doesn’t display a help tag.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the string that’s displayed in a help tag.

    Declaration

    Swift

    var headerToolTip: String?

    Objective-C

    @property(copy) NSString *headerToolTip

    Return Value

    The string displayed in a help tag (also known as a tooltip). The default value is nil.

    Discussion

    If headerToolTip isn’t nil, the string is displayed in a help tag when the pointer pauses over the header of the table column; if headerToolTip is nil, no help tag is displayed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • isResizable - 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 the setMinWidth: and setMaxWidth: methods.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in 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 the setMinWidth: and setMaxWidth: methods.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.4.

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

    Declaration

    Swift

    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.