简体   繁体   English

自定义标题视图与UITableView重叠

[英]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.

相关问题 自定义视图不适合UItableview中的标题 - Custom view is not fit to header in UItableview 在UITableView中设置自定义标题视图 - Setting custom header view in UITableView searchBar与节标题视图重叠 - searchBar overlapped by section header view Objective C UItableView标头自定义视图黑色 - Objective C UItableView header custom view black 如何在带有标题视图和UITableview的自定义视图中正确设置UISearchbar的动画? - How to animate correctly UISearchbar within a custom view with a header view and a UITableview? 部分标题的UITableView自定义视图(内存泄漏)。 什么是使节的标题自定义视图正确的方法? - UITableView custom view for section header (memory leaks). What is correct method to make section's header custom view? 具有动态高度的自定义视图作为UITableView标头ios xcode - Custom View with dynamic Height as UITableView Header ios xcode 更改UITableView自定义标题视图的按钮图像不起作用 - Change UITableView custom header view's button image not working UITableView的自定义节标题视图显示在模拟器上,但不会出现在iPhone上。 - Custom section header view for UITableView appears on simulator, but not on iPhone. UITableView中的自定义标题视图在底部绘制了额外的线条 - the custom header view in my UITableView draws extra lines at bottom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM