我在另一个视图中嵌入了一个 UITableView,如下所示:
I have a UITableView embedded in another view like so:
导航控制器是模态显示的,所以它的布局应该是全屏的,不依赖于故事板的任何其他部分.如果已经使用固定的自动布局约束设置了配置文件视图的上部,如下所示:
The navigation controller is displayed modally, so its layout should be full screen and not depend on any other parts of the storyboard. If have set up the upper part of the profile view with fixed auto-layout constraints like so:
所以基本上,当屏幕变大时,容器视图应该填满剩余空间.
So basically, when the screen is larger, the container view should fill the remaining space.
在容器视图中,我嵌入了一个表视图(包括相应的控制器).为了让问题更明显,我给容器视图一个绿色背景,给表格视图一个蓝色背景(这就是部分标题略带蓝色的原因).当然,我希望表格视图填满整个容器视图.但这只是部分发生:
In the container view, I embedded a Table View (including the appropriate controller). To make the issue more visible, I gave the container view a green background and the table view a blue one (that's why the section heading is slightly blue). Of course, I would expect the table view to fill the entire container view. But this only happens partially:
所以表格视图确实填充了完整的容器视图(表格视图的背景颜色为蓝色),但节标题位于较低的位置.如果我向下滚动,部分标题保持在同一位置,但单元格向上移动并显示在其上方:
So the table view does fill the complete container view (the table view's background color is blue) but the section header is positioned to low. If I scroll down, the section header stays at the same position, but the cells move up and are displayed above it:
我已经尝试检查和取消选中表格视图控制器的扩展边缘"复选框,该复选框控制它是否扩展在顶部栏下"、在底部栏下"和在不透明栏下",但这没有帮助.看起来好像表格视图为导航栏和状态栏留出了空间,但它不应该,而且我不明白如何让它正确地布置节标题和单元格.
I already tried checking and unchecking the "Extended Edges" checkboxes of the table view controller that control whether it extends "Under Top Bars", "Under Bottom Bars" and "Under Opaque Bars", but that did not help. It looks as if the table view leaves space for the navigation bar and status bar, but it shouldn't and I don't understand how I can make it lay out the section header and cells correctly.
任何想法为什么会这样以及如何解决它?
Any ideas why that is and how I can fix it?
这可以通过取消选中 IB 中包含容器视图的控制器而不是表视图控制器的Under Top Bars"框来解决.您应该这样做似乎不正确,因为您会认为在导航栏下扩展主视图(在容器控制器中)不会使嵌入式表格视图的行为方式与它的行为方式相同.
This can be fixed by unchecking the "Under Top Bars" box in IB for the controller that has the container view in it, not the table view controller. It doesn't seem correct that you should have to do this, since, you would think that having the main view (in the container controller) extend under the navigation bar wouldn't make the embedded table view behave the way it does.
这篇关于嵌入在其他视图中的 UITableView 的节标题位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!