UITableView embedded in other view has wrong position of section header

喜你入骨 提交于 2019-12-30 04:47:06

问题


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:

  • top layout guide to image view (the gray one): 20pt
  • image view to "Transactions" label: 20pt
  • "Transactions" label to container view: 20pt
  • container view distance to bottom layout guide, leading and trailing space: all 0pt.

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?


回答1:


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.




回答2:


Disabling "Adjust scroll view insets" of the containing view also helps here.



来源:https://stackoverflow.com/questions/23430279/uitableview-embedded-in-other-view-has-wrong-position-of-section-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!