6

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?

Joachim Kurz
  • 2,875
  • 6
  • 23
  • 43
  • What is that in your table view that has Title---Title---Detail? Is that part of the cell, or something else? – rdelmar May 02 '14 at 15:06
  • it's just another cell type that I actually use in the finished application. The one with title-title-detail is the one that actually holds the data, but since I wanted to make the screenshot without any actual data I quickly introduced a second empty cell type. ;-) The issue exists no matter what cell type I use. – Joachim Kurz May 02 '14 at 15:11
  • OK, that's what I thought. I tried your general set up, and I'm seeing the same strange behavior. This looks like a bug in the way the container view is working in IB. I'm checking out some other ideas, and I'll get back to you if I find anything useful. – rdelmar May 02 '14 at 15:19
  • It's nothing specific with the container view in IB, since I get the same behavior by adding the table view controller in code using the custom container view api. – rdelmar May 02 '14 at 16:01

2 Answers2

22

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • wow, that doesn't make any sense but it works! Thanks a lot. I tried activating the "Under Top Bars" checkbox in the containing view controller, but didn't think about trying it the other way round... – Joachim Kurz May 02 '14 at 18:31
  • 1
    When I did this, the "gap" problem disappeared. However in this case my navigation bar and status bar become oddly grey instead of white as it was before unchecking **Under top bars**. If I turn off the **Translucent** option for the navigation bar, the problem goes away, but thats not the proper solution. – Mitry Aug 28 '14 at 11:05
  • @Mitry, It sounds like you might have another dark view underneath that's showing through the translucent navigation bar. Is the view of the controller with the container view in it, dark? – rdelmar Aug 28 '14 at 15:28
  • 1
    @rdelmar, yes it seems so but there are no view underneath. I specifically recreated the view to ensure that. May be it is home screen? The thing is adding a plain white view under the navigation and status bar solves the problem. But I'm not sure that it is legit. – Mitry Aug 28 '14 at 21:35
3

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

paxos
  • 877
  • 5
  • 11