Reputation: 55
I want to set the value of a slider with the current index of a pageViewController. My idea is to use this method but i dont know how I get the index...
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if(completed)
{
//self.slider.value = THE INDEX;
}
}
Upvotes: 3
Views: 8062
Reputation: 17655
you have to implement the method for getting index. you can do this simply by adding your viewController in NSArray .
NSArray * viewControllers = [NSArray arrayWithObjects:firstViewController,secondViewController, nil];
& then get iindex like this:
self.slider.value=[viewControllers indexOfObject:[pageViewControlle.viewController]];
Upvotes: -1
Reputation: 2272
I think you will have to implement custom method on your datasource, that will return you index of view controller. You very likely have array with ViewControllers in your datasource. so simple call like one below should do :
[pageViewController.datasource indexOfViewControler:[pageViewController.viewControllers]objectAtIndex:0]]; // index of viewcontroller is methond you need to implement on your datascource
Upvotes: 4