title: UIPageViewController: get the currentPage
body: <p>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</p>
  
  <p>I have this <code>UIPageViewController</code> datasource method and I need to use the current index to get the current visible page for delegate method <code>previousViewControllers transitionCompleted:(BOOL)completed</code></p>
  
  <pre><code>- (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;
  }
  </code></pre>
  
  <p>I'm confused about how to write the current index statement from datasource method into delegate method to update current visible page.</p>
  
  <pre><code>- (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;
  }
  </code></pre>
  
  <p>How can I correct this?</p>