Invalid nib registered for identifier

2019-07-22 19:40发布

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.

enter image description here

1条回答
仙女界的扛把子
2楼-- · 2019-07-22 20:37

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

查看更多
登录 后发表回答