diff --git a/Tusker/Screens/Utilities/SplitNavigationController.swift b/Tusker/Screens/Utilities/SplitNavigationController.swift index 4c6c4a64..d916c220 100644 --- a/Tusker/Screens/Utilities/SplitNavigationController.swift +++ b/Tusker/Screens/Utilities/SplitNavigationController.swift @@ -67,6 +67,17 @@ class SplitNavigationController: UIViewController { if let rootViewController { rootNav.viewControllers = [rootViewController] } + + // add the child VCs here, rather than in viewDidLoad, because this VC is added to the UISplitViewController, + // it needs a UINavigationController to be this VC's first child, otherwise it will embed this VC inside + // yet another UINavigationController, which can then cause a crash when we try to embed a nav controller inside + // of ourself (because nested nav controllers are forbidden) + rootNav.willMove(toParent: self) + addChild(rootNav) + rootNav.didMove(toParent: self) + secondaryNav.willMove(toParent: self) + addChild(secondaryNav) + secondaryNav.didMove(toParent: self) } required init?(coder: NSCoder) { @@ -76,10 +87,10 @@ class SplitNavigationController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - embedChild(rootNav, layout: false) - embedChild(secondaryNav, layout: false) rootNav.view.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(rootNav.view) secondaryNav.view.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(secondaryNav.view) separatorView.backgroundColor = .separator separatorView.translatesAutoresizingMaskIntoConstraints = false