A cell in a table view.
- iOS 2.0+
- tvOS 9.0+
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.
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: method or configure the cell with that style in Xcode. To set the text and images of the cell, use the
If you want to go beyond the predefined styles, you can add subviews to the
content 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 property or by changing the inherited
background 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 method of your table view delegate.