UITableViewHeaderFooterView in InterfaceBuilder

It’s absolutely possible and Apple provides an example here.

Download the sample code and look at the SectionHeaderView.xib.

The way to do it is to create a xib with a single UIView on it. Then, set the class type to a class that inherits from UITableViewHeaderFooterView.

Once you have a nib with a class that inherits from UITableViewHeaderFooterView, call the following to register the class for reuse as a header or footer:

static NSString * const SectionHeaderViewIdentifier = @"SectionHeaderViewIdentifier";

[self.tableView registerNib:[UINib nibWithNibName:@"SectionHeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:SectionHeaderViewIdentifier];

To put the view into use, implement the table delegate method tableView:viewForHeaderInSection: like so:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSinteger)section {

    SectionHeaderViewClass *sectionHeaderView = (SectionHeaderView *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionHeaderViewIdentifier];

    // Do stuff...

    return sectionHeaderView;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)