Class

UITable​View​Cell

The UITable​View​Cell class defines the attributes and behavior of the cells that appear in UITable​View objects. This class includes properties and methods for setting and managing cell content and background (including text, images, and custom views), managing the cell selection and highlight state, managing accessory views, and initiating the editing of the cell contents.

Overview

When creating cells, you can customize them yourself or use one of several predefined styles. The predefined cell styles are the simplest option. With the predefined styles, the cell provides label and image subviews whose positions and styling are fixed. All you have to do is provide the text and image content to go into those fixed views. To use a cell with a predefined style, initialize it using the init(style:​reuse​Identifier:​) method or configure the cell with that style in Xcode. To set the text and images of the cell, use the text​Label, detail​Text​Label, and image​View properties.

If you want to go beyond the predefined styles, you can add subviews to the content​View property of the cell. When adding subviews, you are responsible for positioning those views and setting their content yourself.

Whether you use a predefined or custom cell, you can change the cell’s background using the background​View property or by changing the inherited background​Color property. In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the table​View(_:​will​Display:​for​Row​At:​) method of your table view delegate.

For more information about creating cells, see A Closer Look at Table View Cells in Table View Programming Guide for iOS.

Symbols

Initializing a UITableViewCell Object

init(style:​ UITable​View​Cell​Style, reuse​Identifier:​ String?)

Initializes a table cell with a style and a reuse identifier and returns it to the caller.

Reusing Cells

var reuse​Identifier:​ String?

A string used to identify a cell that is reusable.

func prepare​For​Reuse()

Prepares a reusable cell for reuse by the table view'€™s delegate.

Managing the Predefined Content

var text​Label:​ UILabel?

Returns the label used for the main textual content of the table cell.

var detail​Text​Label:​ UILabel?

Returns the secondary label of the table cell if one exists.

var image​View:​ UIImage​View?

Returns the image view of the table cell.

Accessing Views of the Cell Object

var content​View:​ UIView

Returns the content view of the cell object.

var background​View:​ UIView?

The view used as the background of the cell.

var selected​Background​View:​ UIView?

The view used as the background of the cell when it is selected.

var multiple​Selection​Background​View:​ UIView?

The background view to use for a selected cell when the table view allows multiple row selections.

Managing Accessory Views

var accessory​Type:​ UITable​View​Cell​Accessory​Type

The type of standard accessory view the cell should use (normal state).

var accessory​View:​ UIView?

A view that is used, typically as a control, on the right side of the cell (normal state).

var editing​Accessory​Type:​ UITable​View​Cell​Accessory​Type

The type of standard accessory view the cell should use in the table view’s editing state.

var editing​Accessory​View:​ UIView?

A view that is used typically as a control on the right side of the cell when it is in editing mode.

Managing Cell Selection and Highlighting

var is​Selected:​ Bool

A Boolean value that indicates whether the cell is selected.

func set​Selected(Bool, animated:​ Bool)

Sets the selected state of the cell, optionally animating the transition between states.

var is​Highlighted:​ Bool

A Boolean value that indicates whether the cell is highlighted.

func set​Highlighted(Bool, animated:​ Bool)

Sets the highlighted state of the cell, optionally animating the transition between states.

Editing the Cell

var is​Editing:​ Bool

A Boolean value that indicates whether the cell is in an editable state.

func set​Editing(Bool, animated:​ Bool)

Toggles the receiver into and out of editing mode.

var showing​Delete​Confirmation:​ Bool

Returns whether the cell is currently showing the delete-confirmation button.

var shows​Reorder​Control:​ Bool

A Boolean value that determines whether the cell shows the reordering control.

Adjusting to State Transitions

func will​Transition(to:​ UITable​View​Cell​State​Mask)

Called on the cell just before it transitions between cell states.

func did​Transition(to:​ UITable​View​Cell​State​Mask)

Called on the cell just after it transitions between cell states.

Managing Content Indentation

var indentation​Level:​ Int

The indentation level of the cell’s content.

var indentation​Width:​ CGFloat

The width for each level of indentation of a cell'€™s content.

var should​Indent​While​Editing:​ Bool

A Boolean value that controls whether the cell background is indented when the table view is in editing mode.

var separator​Inset:​ UIEdge​Insets

The inset values for the cell’s content.

Managing Focus

var focus​Style:​ UITable​View​Cell​Focus​Style

The appearance of the cell when focused.

Constants

UITable​View​Cell​Style

An enumeration for the various styles of cells.

UITable​View​Cell​Selection​Style

The style of selected cells.

UITable​View​Cell​Editing​Style

The editing control used by a cell.

UITable​View​Cell​Accessory​Type

The type of standard accessory control used by a cell.

UITable​View​Cell​State​Mask

Constants used to determine the new state of a cell as it transitions between states.

UITable​View​Cell​Separator​Style

The style for cells used as separators.

UITable​View​Cell​Focus​Style

The style of focused cells.