UITableViewHeaderFooterView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 6.0 and later.
Declared in
UITableViewHeaderFooterView.h

Overview

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.

Tasks

Initializing the View

Accessing the Content Views

Managing View Reuse

Accessing the Default View Content

Properties

backgroundView

The background view of the header or footer.

@property(nonatomic, retain) UIView *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.
Declared In
UITableViewHeaderFooterView.h

contentView

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

@property(nonatomic, readonly, retain) UIView *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.
Declared In
UITableViewHeaderFooterView.h

detailTextLabel

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

@property(nonatomic, readonly, retain) UILabel *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.
Declared In
UITableViewHeaderFooterView.h

reuseIdentifier

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

@property(nonatomic, readonly, copy) NSString *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.
Declared In
UITableViewHeaderFooterView.h

textLabel

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

@property(nonatomic, readonly, retain) UILabel *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.
Declared In
UITableViewHeaderFooterView.h

tintColor

The tint color of the view.

@property(nonatomic, retain) UIColor *tintColor
Discussion

The default value of this property is nil.

Availability
  • Available in iOS 6.0 and later.
Declared In
UITableViewHeaderFooterView.h

Instance Methods

initWithReuseIdentifier:

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

- (id)initWithReuseIdentifier:(NSString *)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.
Declared In
UITableViewHeaderFooterView.h

prepareForReuse

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

- (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.
Declared In
UITableViewHeaderFooterView.h