Vlad Vlad - 18 days ago 9
iOS Question

UINavigationController buttons disappear when layoutIfNeeded before modal presentation

Odd thing I am noticing:

let navController = UINavigationController(rootViewController: myRootViewController)
navController.view.layoutIfNeeded()
present(navController, animated: true, completion: nil)


In above code I am seeing the navigation controller bar button not showing when I add the layoutIfNeeded()

The reason I am trying to add this is I am finding the root view controller's view lays itself out while the modal presentation is happening. When I add the layoutIfNeeded it does the view layout before presenting which fixes my original problem.

Answer

Try throwing navController.view.layoutIfNeeded() in the viewDidAppear:/viewWillAppear: of the view controller you are presenting and it should fix it.

Comments