title: Why the 20px gap at the top of my UIViewController?
body: <h2>The Problem</h2>
  
  <p>Consider the following controller hierarchy:</p>
  
  <ul>
  <li><code>UINavigationController</code>
  
  <ul>
  <li><code>UIViewController</code>
  
  <ul>
  <li><code>UITableViewController</code></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>The presence of the <code>UIViewController</code> is affecting layout. Without it, the <code>UITableViewController</code> takes up the entire bounds of the <code>UINavigationController</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/UBpsy.png" alt="enter image description here"></p>
  
  <p>However, if I add a vanilla <code>UIViewController</code> between the <code>UINavigationController</code> and <code>UITableViewController</code>, a 20px gap appears between the top of the <code>UIViewController</code> and the top of the <code>UITableViewController</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/R1Pzd.png" alt="enter image description here"></p>
  
  <p>Even if I reduce my code down to the simplest possible thing, I still observe this behavior. Consider this app delegate code:</p>
  
  <pre><code>public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  {
      window = new UIWindow(UIScreen.MainScreen.Bounds);
  
      var tableView = new UITableViewController();
      var intermediateView = new UIViewController();
      var navigation = new UINavigationController(intermediateView);
  
      navigation.View.BackgroundColor = UIColor.Red;
      intermediateView.View.BackgroundColor = UIColor.Green;
      tableView.View.BackgroundColor = UIColor.Blue;
  
      intermediateView.AddChildViewController(tableView);
      intermediateView.View.AddSubview(tableView.View);
      tableView.DidMoveToParentViewController(intermediateView);
  
      window.RootViewController  = navigation;
      window.MakeKeyAndVisible();
  
      return true;
  }
  </code></pre>
  
  <p>The above <em>still</em> shows a 20px gap between the top of the <code>UIView</code> and the top of the <code>UITableView</code>.</p>
  
  <h2>My Understanding of the Problem</h2>
  
  <p>I understand that <em>something</em> is erroneously allocating space for a status bar. Using Reveal I can see that the <code>Frame</code> of the <code>UITableViewController</code> has a <code>Y</code> value of <code>20</code>.</p>
  
  <h2>Things I've Tried</h2>
  
  <h3>Unsuccessful</h3>
  
  <ul>
  <li>Set <code>WantsFullScreenLayout</code> to <code>true</code> on the <code>UIViewController</code>, <code>UITableViewController</code>, and both</li>
  <li>Playing with <code>EdgesForExtendedLayout</code> and <code>ExtendedLayoutIncludesOpaqueBars</code> for both the <code>UIViewController</code> and <code>UITableViewController</code></li>
  <li>Played with <code>AutomaticallyAdjustsScrollViewInsets</code> on the <code>UIViewController</code></li>
  <li>Played with <code>PreservesSuperviewLayoutMargins</code> in the <code>UITableView</code></li>
  <li>Tried overriding <code>PrefersStatusBarHidden</code> and returning <code>true</code> in both the <code>UIViewController</code> and <code>UITableViewController</code></li>
  </ul>
  
  <h3>Successful</h3>
  
  <p>Overriding <code>ViewDidLayoutSubviews</code> in my <code>UITableViewController</code> thusly:</p>
  
  <pre><code>public override void ViewDidLayoutSubviews()
  {
      base.ViewDidLayoutSubviews();
      this.View.Frame = this.View.Superview.Bounds;
  }
  </code></pre>
  
  <h2>Things I want to know</h2>
  
  <ul>
  <li>is there a clean(er) way of achieving my goal?</li>
  <li>what is actually responsible for adding the 20px gap? The <code>UIViewController</code>? The <code>UITableViewController</code>?</li>
  <li>what are the best practices for ensuring my view controllers remain usable in different contexts? Presumably overriding <code>ViewDidLayoutSubviews</code> couples my view controller to expectations as to where it will be displayed in the visual tree. If it were to be hosted higher up the controller stack, things would not look right. Is there a way to avoid this coupling and thus increase reusability?</li>
  </ul>