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.
Initializes a header/footer view with the specified reuse identifier.
A string used to identify a reusable header or footer.
Prepares a reusable header or footer view for reuse by the table.
The content view of the header or footer.
The background view of the header or footer.
A primary text label for the view.
A detail text label for the view.