简体   繁体   中英

Tableview headerview loading from a nib

I have a tableview controller and I was trying load a nib for its headerview in the viewdidload. The code is like:

(void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = self.editButtonItem;


    // Create and set the table header view.
    if (tableHeaderView == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"RZWordDetailHeaderView" owner:self options:nil];
        [tableHeaderView setContentMode:UIViewContentModeScaleAspectFill];

        self.tableView.tableHeaderView = tableHeaderView;
        self.tableView.allowsSelectionDuringEditing = YES;
    }
}

When I run the program, the screen turned out like this image .

It seems that some part of the nib is behind the navigation bar and all the other buttons on the nib view are moved downwards.

Does anyone know how to solve this? Thank you very much.

It doesn't look like tableHeaderView is being set to anything after checking for nil .

Try:

tableHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"RZWordDetailHeaderView"
                                                 owner:self
                                               options:nil] objectAtIndex:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM