简体   繁体   English

UITableView tableViewHeader背景被切断

[英]UITableView tableViewHeader background getting cut off

I have a custom view that I'm trying to load into a tableViewHeader. 我有一个自定义视图,我正在尝试加载到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: 我在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: -setting需要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 我不得不取消选中IB中的Autoresize Subviews: http ://i.imgur.com/jH2bs.png

Maybe you could try: 也许你可以试试:

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

to return your view and the methods that Jacky Boy say to return the header height: 返回你的视图和Jacky Boy说的返回标题高度的方法:

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

Did you try by playing with the autoresizingMask of your view? 您是否尝试过使用autoresizingMask视图? I will add something like this to your code: 我会在你的代码中添加这样的东西:

headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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