I have the issue that the topLayoutGuide.length in a UIViewController (from XIB) gets set after viewWillAppear and i don't know how to hook into the change of topLayoutGuide.length to initially set the contentOffset of a table view.
Code to modally present a UIViewController inside a UINavigationController:
let viewController = UIViewController(nibName: "ViewController", bundle: nil)
let navigationController = UINavigationController(rootViewController: viewController)
present(navigationController, animated: true, completion: nil)
My debugging output about the topLayoutGuide.length
Init view controller
-[UIViewController topLayoutGuide]: guide not available before the view controller's view is loaded
willMove toParentViewController - top layout guide nan
Init navigation controller and pass view controller as root vc
Present navigation controller modally
viewDidLoad - top layout guide 0.0
viewWillAppear - top layout guide 0.0
viewWillLayoutSubviews - top layout guide 64.0
viewDidLayoutSubviews - top layout guide 64.0
viewWillLayoutSubviews - top layout guide 64.0
viewDidLayoutSubviews - top layout guide 64.0
viewDidAppear - top layout guide 64.0
didMove toParentViewController - top layout guide 64.0
viewWillLayoutSubviews - top layout guide 64.0
viewDidLayoutSubviews - top layout guide 64.0
For now i use a bool flag in the view controller to set the contentoffset in the viewDidLayoutSubviews only once, even though the method is called multiple times.
Any more elegant solution in mind?