UITableView inset when parent viewcontroller has a background
<p>I have a tableviewcontroller that I've added as a child ViewController. Its view is added to a containerview (normal UIView). This works great, and it automatically adjusts the top inset:</p>

<p><a href="https://i.stack.imgur.com/MKUi9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MKUi9.png" alt="TableView with correct top inset"></a></p>

<pre><code>override func viewDidLoad() {
    super.viewDidLoad()

    self.title = "ViewController"
    // self.addBackground()

    // Set up container for the tableview
    self.containerView = UIView()
    self.containerView.translatesAutoresizingMaskIntoConstraints = false
    self.containerView.backgroundColor = UIColor.greenColor()
    self.view.addSubview(self.containerView)

    let viewDict = ["container": self.containerView]
    self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[container(100)]", options: [], metrics: nil, views: viewDict))
    self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[container]|", options: [], metrics: nil, views: viewDict))

    // Add tableview controller as child
    tableViewController = TableViewController()
    tableViewController.view.translatesAutoresizingMaskIntoConstraints = false
    self.addChildViewController(tableViewController)
    self.containerView.addSubview(tableViewController.view)
    tableViewController.didMoveToParentViewController(self)

    // Layout
    let tableViewDict = ["child": tableViewController.view]
    self.containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[child]|", options: [], metrics: nil, views: tableViewDict))
    self.containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[child]|", options: [], metrics: nil, views: tableViewDict))
}
</code></pre>

<p>When I add a background image BEFORE adding the containerview, the first couple of rows are hidden behind the navbar.</p>

<pre><code>private func addBackground() {
    let backgroundImage = UIImage(named: "hexley_fork_450")
    let backgroundImageView = UIImageView(image: backgroundImage)
    backgroundImageView.translatesAutoresizingMaskIntoConstraints = false

    self.view.addSubview(backgroundImageView)

    let viewDict = ["backgroundImageView": backgroundImageView]
    let layouts = [
        "H:[backgroundImageView]|",
        "V:[backgroundImageView]|",
    ]

    for layout in layouts {
        self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(layout, options: [], metrics: nil, views: viewDict))
    }
}
</code></pre>

<p>Result:</p>

<p><a href="https://i.stack.imgur.com/th0V4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/th0V4.png" alt="TableView with first couple of rows hidden"></a></p>

<p>Why is this, and how can I prevent it?</p>

<p>Test project on Github: <a href="https://github.com/bvankuik/TestBackgroundLayout" rel="nofollow noreferrer">https://github.com/bvankuik/TestBackgroundLayout</a></p>