From 8094546ad19812845995df9494dee893980728c9 Mon Sep 17 00:00:00 2001 From: ga-tungnguyen Date: Thu, 12 Oct 2017 14:17:39 +0900 Subject: [PATCH] Get index tab selected --- Sources/TabPageViewController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/TabPageViewController.swift b/Sources/TabPageViewController.swift index 2bcabc1..48f4acf 100644 --- a/Sources/TabPageViewController.swift +++ b/Sources/TabPageViewController.swift @@ -12,7 +12,8 @@ open class TabPageViewController: UIPageViewController { open var isInfinity: Bool = false open var option: TabPageOption = TabPageOption() open var tabItems: [(viewController: UIViewController, title: String)] = [] - + open var indexSelected: ((Int) -> Void)? + var currentIndex: Int? { guard let viewController = viewControllers?.first else { return nil @@ -179,6 +180,7 @@ extension TabPageViewController { tabView.updateCurrentIndex(beforeIndex, shouldScroll: true) tabView.pageItemPressedBlock = { [weak self] (index: Int, direction: UIPageViewControllerNavigationDirection) in + self?.indexSelected?(index) self?.displayControllerWithIndex(index, direction: direction, animated: true) } @@ -296,7 +298,7 @@ extension TabPageViewController: UIPageViewControllerDataSource { guard var index = tabItems.map({$0.viewController}).index(of: viewController) else { return nil } - + self.indexSelected?(index) if isAfter { index += 1 } else {