Current index of PageViewController

I want to set the value of the slider with the current index of the pageViewController. My idea is to use this method, but I don't know how to get the index ...

-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{

    if(completed)
    {

        //self.slider.value = THE INDEX;
    }
}

      

+3


source to share


2 answers


I think you will have to implement a custom method on your datasource that will return the view controller index to you. You probably have an array with ViewControllers in your datasource. so a simple call like below should do:



[pageViewController.datasource indexOfViewControler:[pageViewController.viewControllers]objectAtIndex:0]]; // index of viewcontroller is methond you need to implement on your datascource

      

+4


source


you need to implement a method to get the index. you can do it just by adding your viewController to NSArray.

NSArray * viewControllers = [NSArray arrayWithObjects:firstViewController,secondViewController, nil];

      



& then get iindex like this:

self.slider.value=[viewControllers indexOfObject:[pageViewControlle.viewController]];

      

-1


source







All Articles