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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…