Invalid nib registered for identifier

2019-07-22 20:18发布

问题:

I'm trying to get a view created in a nib file to be used as a section header in my UITableView. I'm following the 3rd option as described here

http://hons82.blogspot.it/2014/05/uitableviewheader-done-right.html

But I'm getting this error

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (sectionHeaderIndentifier) - nib must contain exactly one top level object which must be a UITableViewHeaderFooterView instance'

Here's the code I'm using

 UINib *sectionHeaderNib = [UINib nibWithNibName:@"headerNib" bundle:nil];

    NSString *SectionHeaderViewIdentifier = @"sectionHeaderIndentifier";

    [self.tableView registerNib:sectionHeaderNib forHeaderFooterViewReuseIdentifier:SectionHeaderViewIdentifier];

and

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

    NSString *SectionHeaderViewIdentifier = @"sectionHeaderIndentifier";

    HeaderSection *sectionHeaderView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionHeaderViewIdentifier];


    return sectionHeaderView;
}

And here's a screen shot of my nib file.

回答1:

The message says the root view (not file's owner) must be specifically an instance of UITableViewHeaderFooterView.