iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UITableViewHeaderFooterView Class Reference

Options
Deployment Target:

On This Page
Language:

UITableViewHeaderFooterView

The UITableViewHeaderFooterView class implements a reusable view that can be placed at the top or bottom of a table section. You use headers and footers to display additional information for that section.

You can use this class as-is without subclassing in most cases. If you have custom content to display, create the subviews for your content and add them to the view in the contentView property. You can also assign an optional background view to the backgroundView property. If you do not want to add custom subviews you can use the textLabel property to display some descriptive text in the view. Tables in grouped style additionally support the detailTextLabel property.

To make the table view aware of your header or footer view, you need to register it. You do this using the registerNib:forHeaderFooterViewReuseIdentifier: or registerClass:forHeaderFooterViewReuseIdentifier: method of UITableView.

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

    Declaration

    Swift

    init(reuseIdentifier reuseIdentifier: String?)

    Objective-C

    - (instancetype _Nonnull)initWithReuseIdentifier:(NSString * _Nullable)reuseIdentifier

    Parameters

    reuseIdentifier

    A string used to identify the header or footer view if it is to be reused by multiple sections. Pass nil if the view is not to be reused. You should use the same reuse identifier for all header or footer views of the same form.

    Return Value

    An initialized UITableViewHeaderFooterView object or nil if the object could not be created.

    Discussion

    Once set, you cannot change the reuse identifier for the returned view object.

    Availability

    Available in iOS 6.0 and later.

  • The content view of the header or footer. (read-only)

    Declaration

    Swift

    var contentView: UIView { get }

    Objective-C

    @property(nonatomic, readonly, strong) UIView * _Nonnull contentView

    Discussion

    To create your header or footer content, you add subviews to the view in this property. Your custom subviews represent the main content of your header or footer. It is your responsibility to configure all subviews.

    Availability

    Available in iOS 6.0 and later.

  • The background view of the header or footer.

    Declaration

    Swift

    var backgroundView: UIView?

    Objective-C

    @property(nonatomic, strong) UIView * _Nullable backgroundView

    Discussion

    The view in this property is placed behind the view in the contentView property and used to display static background content behind the header or footer. For example, you might assign an image view to this property and use it to display a custom background image.

    Availability

    Available in iOS 6.0 and later.

  • A string used to identify a reusable header or footer. (read-only)

    Declaration

    Swift

    var reuseIdentifier: String? { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSString * _Nullable reuseIdentifier

    Discussion

    You assign a reuse identifier to a header or footer view at creation time. Once assigned, the table view uses that reuse identifier to gather your views when they are scrolled offscreen and queue them for later reuse. You can retrieve header or footer views by passing the same reuse identifier to the dequeueReusableHeaderFooterViewWithIdentifier: method of the table view.

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func prepareForReuse()

    Objective-C

    - (void)prepareForReuse

    Discussion

    If your header or footer view is reusable—that is, it has a reuse identifier—the table view calls this method just before returning the view from its dequeueReusableHeaderFooterViewWithIdentifier: method. Subclasses can override this method and use it to reset attributes of the view to their default values. For performance reasons, you should only reset attributes that are not related to content.

    If the view does not have a reuse identifier, this method is never called.

    Availability

    Available in iOS 6.0 and later.

  • A primary text label for the view. (read-only)

    Declaration

    Swift

    var textLabel: UILabel? { get }

    Objective-C

    @property(nonatomic, readonly, strong) UILabel * _Nullable textLabel

    Discussion

    Accessing the value in this property causes the view to create a default label for displaying a detail text string. If you are managing the content of the view yourself by adding subviews to the contentView property, you should not access this property.

    The label is sized to fit the content view area in the best way possible based on the size of the string. Its size is also adjusted depending on whether there is a detail text label present.

    Availability

    Available in iOS 6.0 and later.

  • A detail text label for the view. (read-only)

    Declaration

    Swift

    var detailTextLabel: UILabel? { get }

    Objective-C

    @property(nonatomic, readonly, strong) UILabel * _Nullable detailTextLabel

    Discussion

    This property is only used for tables configured with UITableViewStyleGrouped.

    Accessing the value in this property causes the view to create a default label for displaying a detail text string. If you are managing the content of the view yourself by adding subviews to the contentView property, you should not access this property.

    The label is sized to fit the content view area in the best way possible based on the size of the string. Its size is also adjusted depending on whether there is a primary text label present.

    Availability

    Available in iOS 6.0 and later.

  • The tint color of the view.

    Declaration

    Swift

    var tintColor: UIColor!

    Objective-C

    @property(nonatomic, strong) UIColor * _Null_unspecified tintColor

    Discussion

    The default value of this property is nil.

    Availability

    Available in iOS 6.0 and later.