[英]Custom header view overlapped by UITableView
In interface builder I have a header view above my UITableView, however in the simulator it is missing, and the Table View seems to be over it since it takes up most of the screen. 在界面生成器中,我的UITableView上方有一个标题视图,但是在模拟器中却不见了,而Table View似乎在其上方,因为它占据了大部分屏幕。 Any reason for this?
有什么原因吗? Work around?
变通吗?
Interface Builder 界面生成器
Simulator 仿真器
In your case: 在您的情况下:
From your interface builder image I can see that table view is subview of view and you header view is also subview of tableview. 从界面构建器图像中,我可以看到表视图是视图的子视图,而标题视图也是表视图的子视图。 It happening because tableview is hiding the header view.
发生这种情况是因为tableview隐藏了标题视图。 if you add the header view as subview of tableview then it would appear.
如果将标题视图添加为tableview的子视图,则它将出现。 But adding subview will not solve your problem because when you will scroll the tableview the subview will be gone.
但是添加子视图将不能解决您的问题,因为当您滚动表视图时,子视图将消失。
For solving your problem as I can see that you have a navigation bar in your table view you can add the header view as subview of UINavigationBar
. 如我所见,为了解决您的问题,您可以在表视图中有一个导航栏,可以将标题视图添加为
UINavigationBar
子视图。
[self.navigationController.view addSubview:headerView];
Good Practise: 良好作法:
Set the header view for section. 设置节的标题视图。 Then you don't need to set any custom view at the top of your tableview.
然后,您无需在表视图的顶部设置任何自定义视图。 Try this:
尝试这个:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *aView = [[UIView alloc] init];
//Customize the view according to our requirment
return aView;
}
Also implement this: 还要实现这一点:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44.f; // Make this height as you need. Or else you may not see the full view.
}
Btw you can create a subclass of UITableViewController
instead of UIViewController
. 顺便说一句,您可以创建
UITableViewController
的子类而不是UIViewController
。 Hope this helps.. :) 希望这可以帮助.. :)
Deselect Extend Edges / Under Top Bars 取消选择延伸边缘/顶部栏下方
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.