From 4fa1bd7268a2923357dcc3837ee0b41fe75484fa Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 11 Jul 2022 14:59:01 -0400 Subject: [PATCH] Fix crash due to nested navigation controllers --- .../Utilities/SplitNavigationController.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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