viewControllerBeforeViewController is not called e

2019-06-14 05:50发布

问题:

I have implemented UIPageViewController in my application.

I have implemented two delegate methods which returns view for particular Index.

And Also i am detecting forward and backward direction from these methods.

  - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController  viewControllerBeforeViewController:(UIViewController *)viewController

  - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController

Now the problem is that sometimes viewControllerBeforeViewController and viewControllerAfterViewController are not called but Pagination works fine. Due to this i am not able to find Direction.

Also I have implemented Custom Page Control and I am finding current Index from these methods. When These method not called my PageControl is now working find.

I am not able to find any solution for this.

回答1:

Some how I manage to find the Index in this delegate method.

Whenever I am returning ViewController for PageController I am setting its Index value in respective view controller and Finding this Index as:

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

    UIViewController * viewController = [pageViewController.viewControllers lastObject];

    CustomViewController *childCtrlr = (CustomViewController*)viewController;

    NSUInteger currentPageIndex = [(CustomViewController *)viewController index];

}