Class

UITableViewHeaderFooterView

A reusable view that you place at the top or bottom of a table section to display additional information for that section.

Declaration

class UITableViewHeaderFooterView : UIView

Overview

Use UITableViewHeaderFooterView objects to manage the header and footer content of your table's sections efficiently. A header-footer view is a reusable view that you can subclass or use as is. To generate a header or footer with a standard appearance, configure the textLabel property with the text you want to display. (If you configured your table view with the group style, you can also configure the detailTextLabel property.) To generate a more custom appearance, add subviews to the view in the contentView property. You can also assign an optional background view to the backgroundView property.

To promote the reuse of your header-footer views, register them by calling the register(_:forHeaderFooterViewReuseIdentifier:) or register(_:forHeaderFooterViewReuseIdentifier:) method of the table view. In the tableView(_:viewForHeaderInSection:) or tableView(_:viewForFooterInSection:) method of your delegate object, call the table view's dequeueReusableHeaderFooterView(withIdentifier:) method to create your view. That method returns a recycled view (if one is available) or creates a new view using the information you registered.

A simple alternative to creating custom header-footer views is to implement the tableView(_:titleForHeaderInSection:) and tableView(_:titleForFooterInSection:) methods of your data source object. When you implement those methods, the table view creates a standard header or footer view and displays the text you supply.

Topics

Creating the View

init(reuseIdentifier: String?)

Initializes a header/footer view with the specified reuse identifier.

Managing View Reuse

var reuseIdentifier: String?

A string used to identify a reusable header or footer.

func prepareForReuse()

Prepares a reusable header or footer view for reuse by the table.

Accessing the Content Views

var contentView: UIView

The content view of the header or footer.

var backgroundView: UIView?

The background view of the header or footer.

Configuring the Default Content Views

var textLabel: UILabel?

A primary text label for the view.

var detailTextLabel: UILabel?

A detail text label for the view.

See Also

Cells, Headers, and Footers

Configuring the Cells for Your Table

Specify the appearance and content of your table’s rows by defining one or more prototype cells in your storyboard.

Creating Self-Sizing Table View Cells

Create table view cells that support Dynamic Type and use system spacing constraints to adjust the spacing surrounding text labels.

Adding Headers and Footers to Table Sections

Differentiate groups of rows visually by adding header and footer views to your table view’s sections.

class UITableViewCell

The visual representation of a single row in a table view.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software