简体   繁体   中英

UITableView tableViewHeader background getting cut off

I have a custom view that I'm trying to load into a tableViewHeader. The strange thing is that the bottom of the background is always getting cut off. It's as if the nav bar is pushing the buttons down, but not the rest of the view.

The nib looks like this:

笔尖图像

I'm setting it like this in my tableviewcontroller:

[[NSBundle mainBundle] loadNibNamed:@"MenuNav" owner:self options:nil];
[self.tableView setTableHeaderView:headerView];

This is what it looks like in the simulator. The buttons are also not handling clicks in the bottom half.

模拟器中的图像

What I have tried: -bringing the subview to the front:

[self.tableView bringSubviewToFront:headerView];

-setting needs layout for the tableview:

[self.tableView setNeedsLayout]

-I have also checked that the view's frame is correct.

Any Ideas? thanks!

Edit

I found the culprit. I had to uncheck Autoresize Subviews in IB: http://i.imgur.com/jH2bs.png

Maybe you could try:

  • (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

to return your view and the methods that Jacky Boy say to return the header height:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

Did you try by playing with the autoresizingMask of your view? I will add something like this to your code:

headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

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