PageViewController current page index in Swift

LeNI picture LeNI · Sep 28, 2015 · Viewed 42.7k times · Source

I want to get current index of a pageViewController, I don't know how I get the visible pages index.

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool,previousViewControllers: [UIViewController],transitionCompleted completed: Bool)
{
    // How to get it?

}

Answer

manukv picture manukv · Sep 28, 2015

You can use didFinishAnimating, and set tags to viewcontrollers. try this

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
{
   if (!completed)
  {
    return
  }
  self.pageControl.currentPageIndex = pageViewController.viewControllers!.first!.view.tag //Page Index
}