Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView embedded in other view has wrong position of section header

I have a UITableView embedded in another view like so:

storbyboard showing both parent and embedded view controller

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:

app screenshot showing that table view does fill the complete container view, but section header is positioned too low

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:

app screenshot after scrolling in table view

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?

like image 772
Joachim Kurz Avatar asked May 02 '14 14:05

Joachim Kurz


2 Answers

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.

like image 129
rdelmar Avatar answered Oct 22 '22 19:10

rdelmar


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

like image 3
paxos Avatar answered Oct 22 '22 20:10

paxos