From f1a6a405c2226d316a332fbc6c33406f026d2bf5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 5 Sep 2023 20:47:11 -0400 Subject: [PATCH] Fix crash when split VC collapses with multi-column nav controller --- Tusker/Screens/Main/MainSplitViewController.swift | 1 + .../Utilities/MultiColumnNavigationController.swift | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index d342ce0b..63a806fe 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -169,6 +169,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate { var itemNavStack: [UIViewController] if item == sidebar.selectedItem { itemNavStack = secondaryNavController.viewControllers + secondaryNavController.viewControllers = [] } else { itemNavStack = navigationStacks[item] ?? [] navigationStacks.removeValue(forKey: item) diff --git a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift index 2f2858ef..0f07f24b 100644 --- a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift +++ b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift @@ -121,7 +121,11 @@ class MultiColumnNavigationController: UIViewController { } private func scrollToEnd(animated: Bool) { - scrollColumnToEnd(columnIndex: viewControllers.count - 1, animated: animated) + if viewControllers.isEmpty { + scrollView.setContentOffset(.init(x: -scrollView.adjustedLeadingContentInset, y: -scrollView.adjustedContentInset.top), animated: false) + } else { + scrollColumnToEnd(columnIndex: viewControllers.count - 1, animated: animated) + } } private func scrollColumnToEnd(columnIndex: Int, animated: Bool) { @@ -233,7 +237,7 @@ private class ColumnView: UIView { } func setContent(_ viewController: UIViewController, needsCloseButton: Bool) { - guard viewController !== contentViewController else { + guard viewController !== contentViewController || viewController.parent !== navigationController else { return }