So I'm experiencing a bit of an odd (in my opinion) issue. I have a standard UINavigationController with a root UIViewController.
I'm adding a UITableView programatically to the view controller. When I set the frame of the table view, I set it as:
tableView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
When I run the simulator, sometimes the tableview is positioned perfectly - sitting just under the navigation bar. However, sometimes (seemingly at random) the tableview is positioned at the top of the screen, beneath the navigation bar.
I've tried to change the Y coordinate of the tableview to be
(self.navigationController?.navigationBar.frame.height)!
But now the reverse happens: sometimes the tableview is positioned correctly, but sometimes a navigation bar sized gap appears under the navigation bar, above the tableview.
I'm pretty lost as to what's happening - perhaps it's something to do with when the navigation bar is created?
Thanks in advance.