---
title: NSMatrix
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsmatrix
---

# NSMatrix

A legacy interface for grouping radio buttons or other types of cells together.

## Declaration

```swift
class NSMatrix
```

## Overview

Overview important: Use of NSMatrix is discouraged in apps that run in macOS 10.8 and later. If you need to create a radio button group in an app that runs in macOS 10.8 and later, create instances of NSButton that each specify a button type of NSRadioButton and specify the same action and the same superview for each button in the group. NSMatrix uses flipped coordinates by default. The cells in an NSMatrix object are numbered by row and column, each starting with 0; for example, the top left NSCell would be at (0, 0), and the NSCell that’s second down and third across would be at (1, 2). The NSMatrix class has the notion of a single selected cell, which is the cell that was most recently clicked or that was so designated by a selectCell(atRow:column:) or selectCell(withTag:) message. The selected cell is the cell chosen for action messages except for performClick(_:) (NSCell), which is assigned to the key cell. (The key cell is generally identical to the selected cell, but can be given click focus while leaving the selected cell unchanged.) If the user has selected multiple cells, the selected cell is the one lowest and furthest to the right in the matrix of cells.

## Topics

### Initializing an NSMatrix Object

- [init(frame:)](appkit/nsmatrix/init(frame:).md)
- [init(frame:mode:cellClass:numberOfRows:numberOfColumns:)](appkit/nsmatrix/init(frame:mode:cellclass:numberofrows:numberofcolumns:).md)
- [init(frame:mode:prototype:numberOfRows:numberOfColumns:)](appkit/nsmatrix/init(frame:mode:prototype:numberofrows:numberofcolumns:).md)

### Configuring the Matrix Object

- [mode](appkit/nsmatrix/mode-swift.property.md)
- [allowsEmptySelection](appkit/nsmatrix/allowsemptyselection.md)
- [isSelectionByRect](appkit/nsmatrix/isselectionbyrect.md)

### Managing the Cell Class

- [cellClass](appkit/nsmatrix/cellclass.md)
- [prototype](appkit/nsmatrix/prototype.md)

### Laying Out the Cells of the Matrix

- [addColumn()](appkit/nsmatrix/addcolumn().md)
- [addColumn(with:)](appkit/nsmatrix/addcolumn(with:).md)
- [addRow()](appkit/nsmatrix/addrow().md)
- [addRow(with:)](appkit/nsmatrix/addrow(with:).md)
- [cellFrame(atRow:column:)](appkit/nsmatrix/cellframe(atrow:column:).md)
- [cellSize](appkit/nsmatrix/cellsize.md)
- [getNumberOfRows(_:columns:)](appkit/nsmatrix/getnumberofrows(_:columns:).md)
- [insertColumn(_:)](appkit/nsmatrix/insertcolumn(_:).md)
- [insertColumn(_:with:)](appkit/nsmatrix/insertcolumn(_:with:).md)
- [insertRow(_:)](appkit/nsmatrix/insertrow(_:).md)
- [insertRow(_:with:)](appkit/nsmatrix/insertrow(_:with:).md)
- [intercellSpacing](appkit/nsmatrix/intercellspacing.md)
- [makeCell(atRow:column:)](appkit/nsmatrix/makecell(atrow:column:).md)
- [numberOfColumns](appkit/nsmatrix/numberofcolumns.md)
- [numberOfRows](appkit/nsmatrix/numberofrows.md)
- [putCell(_:atRow:column:)](appkit/nsmatrix/putcell(_:atrow:column:).md)
- [removeColumn(_:)](appkit/nsmatrix/removecolumn(_:).md)
- [removeRow(_:)](appkit/nsmatrix/removerow(_:).md)
- [renewRows(_:columns:)](appkit/nsmatrix/renewrows(_:columns:).md)
- [sort(using:context:)](appkit/nsmatrix/sort(using:context:).md)
- [sort(using:)](appkit/nsmatrix/sort(using:).md)

### Auto Layout Sizing

- [autorecalculatesCellSize](appkit/nsmatrix/autorecalculatescellsize.md)

### Finding Matrix Coordinates

- [getRow(_:column:for:)](appkit/nsmatrix/getrow(_:column:for:).md)
- [getRow(_:column:of:)](appkit/nsmatrix/getrow(_:column:of:).md)

### Managing Attributes of Individual Cells

- [setState(_:atRow:column:)](appkit/nsmatrix/setstate(_:atrow:column:).md)
- [setToolTip(_:for:)](appkit/nsmatrix/settooltip(_:for:).md)
- [toolTip(for:)](appkit/nsmatrix/tooltip(for:).md)

### Selecting and Deselecting Cells

- [selectCell(atRow:column:)](appkit/nsmatrix/selectcell(atrow:column:).md)
- [selectCell(withTag:)](appkit/nsmatrix/selectcell(withtag:).md)
- [selectAll(_:)](appkit/nsmatrix/selectall(_:).md)
- [keyCell](appkit/nsmatrix/keycell.md)
- [setSelectionFrom(_:to:anchor:highlight:)](appkit/nsmatrix/setselectionfrom(_:to:anchor:highlight:).md)
- [deselectAllCells()](appkit/nsmatrix/deselectallcells().md)
- [deselectSelectedCell()](appkit/nsmatrix/deselectselectedcell().md)

### Finding Cells

- [selectedCells](appkit/nsmatrix/selectedcells.md)
- [selectedColumn](appkit/nsmatrix/selectedcolumn.md)
- [selectedRow](appkit/nsmatrix/selectedrow.md)
- [cell(atRow:column:)](appkit/nsmatrix/cell(atrow:column:).md)
- [cell(withTag:)](appkit/nsmatrix/cell(withtag:).md)
- [cells](appkit/nsmatrix/cells.md)

### Modifying Graphics Attributes

- [backgroundColor](appkit/nsmatrix/backgroundcolor.md)
- [cellBackgroundColor](appkit/nsmatrix/cellbackgroundcolor.md)
- [drawsBackground](appkit/nsmatrix/drawsbackground.md)
- [drawsCellBackground](appkit/nsmatrix/drawscellbackground.md)

### Editing Text in Cells

- [selectText(_:)](appkit/nsmatrix/selecttext(_:).md)
- [selectText(atRow:column:)](appkit/nsmatrix/selecttext(atrow:column:).md)
- [textShouldBeginEditing(_:)](appkit/nsmatrix/textshouldbeginediting(_:).md)
- [textDidBeginEditing(_:)](appkit/nsmatrix/textdidbeginediting(_:).md)
- [textDidChange(_:)](appkit/nsmatrix/textdidchange(_:).md)
- [textShouldEndEditing(_:)](appkit/nsmatrix/textshouldendediting(_:).md)
- [textDidEndEditing(_:)](appkit/nsmatrix/textdidendediting(_:).md)

### Setting Tab Key Behavior

- [tabKeyTraversesCells](appkit/nsmatrix/tabkeytraversescells.md)

### Managing the Delegate

- [delegate](appkit/nsmatrix/delegate.md)
- [NSMatrixDelegate](appkit/nsmatrixdelegate.md)

### Resizing the Matrix and Its Cells

- [autosizesCells](appkit/nsmatrix/autosizescells.md)
- [setValidateSize(_:)](appkit/nsmatrix/setvalidatesize(_:).md)
- [sizeToCells()](appkit/nsmatrix/sizetocells().md)

### Scrolling Cells in the Matrix

- [isAutoscroll](appkit/nsmatrix/isautoscroll.md)
- [setScrollable(_:)](appkit/nsmatrix/setscrollable(_:).md)
- [scrollCellToVisible(atRow:column:)](appkit/nsmatrix/scrollcelltovisible(atrow:column:).md)

### Displaying and Highlighting Cells

- [drawCell(atRow:column:)](appkit/nsmatrix/drawcell(atrow:column:).md)
- [highlightCell(_:atRow:column:)](appkit/nsmatrix/highlightcell(_:atrow:column:).md)

### Managing and Sending Action Messages

- [sendAction()](appkit/nsmatrix/sendaction().md)
- [sendAction(_:to:forAllCells:)](appkit/nsmatrix/sendaction(_:to:forallcells:).md)
- [doubleAction](appkit/nsmatrix/doubleaction.md)
- [sendDoubleAction()](appkit/nsmatrix/senddoubleaction().md)

### Handling Event and Action Messages

- [acceptsFirstMouse(for:)](appkit/nsmatrix/acceptsfirstmouse(for:).md)
- [mouseDown(with:)](appkit/nsmatrix/mousedown(with:).md)
- [mouseDownFlags](appkit/nsmatrix/mousedownflags.md)
- [performKeyEquivalent(with:)](appkit/nsmatrix/performkeyequivalent(with:).md)

### Managing the Cursor

- [resetCursorRects()](appkit/nsmatrix/resetcursorrects().md)

### Constants

- [NSMatrix.Mode](appkit/nsmatrix/mode-swift.enum.md)

### Instance Methods

- [selectedCell()](appkit/nsmatrix/selectedcell().md)

## Relationships

### Inherits From

- [NSControl](appkit/nscontrol.md)

### Inherited By

- [NSForm](appkit/nsform.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSAccessibilityElementProtocol](appkit/nsaccessibilityelementprotocol.md)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [NSUserInterfaceValidations](appkit/nsuserinterfacevalidations.md)
- [NSViewToolTipOwner](appkit/nsviewtooltipowner.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Controls

- [Responding to control-based events using target-action](uikit/responding-to-control-based-events-using-target-action.md)
- [NSButton](appkit/nsbutton.md)
- [NSColorWell](appkit/nscolorwell.md)
- [Combo Box](appkit/combo-box.md)
- [NSComboButton](appkit/nscombobutton.md)
- [Date Picker](appkit/date-picker.md)
- [NSImageView](appkit/nsimageview.md)
- [NSLevelIndicator](appkit/nslevelindicator.md)
- [Path Control](appkit/path-control.md)
- [NSPopUpButton](appkit/nspopupbutton.md)
- [NSProgressIndicator](appkit/nsprogressindicator.md)
- [NSRuleEditor](appkit/nsruleeditor.md)
- [NSPredicateEditor](appkit/nspredicateeditor.md)
- [Search Field](appkit/search-field.md)
- [NSSegmentedControl](appkit/nssegmentedcontrol.md)
