forked from shadowfacts/Tusker
Fix apparent crash when tapping tab bar item of selected tab
This commit is contained in:
parent
4fa1bd7268
commit
af2e95ea39
|
@ -13,11 +13,13 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
let titles: [String]
|
let titles: [String]
|
||||||
let pageControllers: [UIViewController]
|
let pageControllers: [UIViewController]
|
||||||
|
|
||||||
private(set) var currentIndex: Int!
|
private(set) var currentIndex = 0
|
||||||
|
|
||||||
var segmentedControl: UISegmentedControl!
|
var segmentedControl: UISegmentedControl!
|
||||||
|
|
||||||
init(titles: [String], pageControllers: [UIViewController]) {
|
init(titles: [String], pageControllers: [UIViewController]) {
|
||||||
|
precondition(!pageControllers.isEmpty)
|
||||||
|
|
||||||
self.titles = titles
|
self.titles = titles
|
||||||
self.pageControllers = pageControllers
|
self.pageControllers = pageControllers
|
||||||
|
|
||||||
|
@ -41,7 +43,6 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
|
|
||||||
view.backgroundColor = .systemBackground
|
view.backgroundColor = .systemBackground
|
||||||
|
|
||||||
segmentedControl.selectedSegmentIndex = 0
|
|
||||||
selectPage(at: 0, animated: false)
|
selectPage(at: 0, animated: false)
|
||||||
|
|
||||||
addKeyCommand(MenuController.prevSubTabCommand)
|
addKeyCommand(MenuController.prevSubTabCommand)
|
||||||
|
@ -56,7 +57,7 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectPage(at index: Int, animated: Bool) {
|
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)
|
setViewControllers([pageControllers[index]], direction: direction, animated: animated)
|
||||||
navigationItem.title = pageControllers[index].title
|
navigationItem.title = pageControllers[index].title
|
||||||
currentIndex = index
|
currentIndex = index
|
||||||
|
|
Loading…
Reference in New Issue