UIPageViewController: get the currentPage
ios6, iphone, objective-c
Solution
It looks like you should be able to get the current index with:
ContentViewController *viewController = [self.pageViewController.viewControllers lastObject];
currentIndex = [modelArray indexOfObject:[viewController page]];
Problem
I have been struggling with this issue for the last few days and after all this juggling I have figured out that all I need is the current Index from the datasource method to update with current visible page number I have this `UIPageViewController` datasource method and I need to use the current index to get the current visible page for delegate method `previousViewControllers transitionCompleted:(BOOL)completed` ``` - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSString *path = [[NSBundle mainBundle] pathForResource:@"pages" ofType:@"pdf"]; NSURL *pdfurl = [NSURL fileURLWithPath:path]; PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfurl); contentViewController = [[ContentViewController alloc] initWithPDFAtPath:path]; currentIndex = [modelArray indexOfObject:[(ContentViewController *)viewController page]]; if (currentIndex == totalPages - 1) { return nil; } contentViewController.page = [modelArray objectAtIndex:currentIndex + 1]; return contentViewController; } ``` I'm confused about how to write the current index statement from datasource method into delegate method to update current visible page. ``` - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{ if (!completed) { return; } //currentIndex = [[self.pageViewController.viewController lastObject]]; currentIndex = [self indexOfObject:contentViewController]; [self displaycurrentIndex:currentIndex]; //self.pageControl.currentPage = currentIndex; } ``` How can I correct this?