Contents

tableView(_:titleForHeaderInSection:)

Asks the data source for the title of the header of the specified section of the table view.

Declaration

optional func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?

Parameters

  • tableView:

    The table-view object asking for the title.

  • section:

    An index number identifying a section of tableView.

Mentioned in

Return Value

A string to use as the title of the section header. If you return nil , the section will have no title.

Discussion

The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView(_:viewForHeaderInSection:) instead.

If you don’t implement this method or the tableView(_:viewForHeaderInSection:) method, the table doesn’t display headers for sections. If you implement both methods, the tableView(_:viewForHeaderInSection:) method takes priority.

See Also

Providing cells, headers, and footers