1

The code is pretty streight forward:

HGUserInfoHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"HeaderView"
                                                                 owner:self
                                                               options:nil] firstObject];

self.tableView.tableHeaderView = headerView;

And the HeadView nib file is like this:Imgur

But it turns out to be like this:Imgur

Winter
  • 1,004
  • 8
  • 13

2 Answers2

1

After struggling for several hours today,finally I found out that I need to wrap the headerview with a dummy view,the code is like this:

HGUserInfoHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"HeaderView"
                                                                 owner:self
                                                               options:nil] firstObject];

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 130)];
[dummyView addSubview:headerView];

self.tableView.tableHeaderView = dummyView;

And then the header view shows properly:Imgur.
This link also helped me,but the question is quite different.
So I decide to post my problem and solution here in case anyone need it.

Community
  • 1
  • 1
Winter
  • 1,004
  • 8
  • 13
0

Are you referring to the gray background?

If so, your NIB is incomplete. The headerView is transparent or uses clearColor instead of white.

For issues like this, you could use SparkInspector.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179