From af2e95ea394b6bb71eee087a21690bb0b2a1743b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 11 Jul 2022 15:07:11 -0400 Subject: [PATCH] Fix apparent crash when tapping tab bar item of selected tab --- Tusker/Screens/Utilities/SegmentedPageViewController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Utilities/SegmentedPageViewController.swift b/Tusker/Screens/Utilities/SegmentedPageViewController.swift index d7550782cf..b5dd159ad7 100644 --- a/Tusker/Screens/Utilities/SegmentedPageViewController.swift +++ b/Tusker/Screens/Utilities/SegmentedPageViewController.swift @@ -13,11 +13,13 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel let titles: [String] let pageControllers: [UIViewController] - private(set) var currentIndex: Int! + private(set) var currentIndex = 0 var segmentedControl: UISegmentedControl! init(titles: [String], pageControllers: [UIViewController]) { + precondition(!pageControllers.isEmpty) + self.titles = titles self.pageControllers = pageControllers @@ -41,7 +43,6 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel view.backgroundColor = .systemBackground - segmentedControl.selectedSegmentIndex = 0 selectPage(at: 0, animated: false) addKeyCommand(MenuController.prevSubTabCommand) @@ -56,7 +57,7 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel } func selectPage(at index: Int, animated: Bool) { - let direction: UIPageViewController.NavigationDirection = currentIndex == nil ? .forward : index - currentIndex > 0 ? .forward : .reverse + let direction: UIPageViewController.NavigationDirection = index - currentIndex > 0 ? .forward : .reverse setViewControllers([pageControllers[index]], direction: direction, animated: animated) navigationItem.title = pageControllers[index].title currentIndex = index