UIPageViewController: get the currentPage

后端 未结 12 532
别那么骄傲
别那么骄傲 2021-02-03 22:22

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 up

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 22:44

    I am facing the same issue on pageViewController, everytime i swipe my pageViewController it calls my delegate twice and am not able to find the issue. And my array is dynamic so i want the proper index value from pageController. First of all set the delegate of your pageViewController. Like this :-

    self.pageViewController.delegate = self;
    

    And then add this delegate method to your class

    - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
    {
    if (completed) {
        NSInteger currentIndex = ((PageContentViewController *)self.pageViewController.viewControllers.firstObject).pageIndex;
    
        NSLog(@"%ld",(long)currentIndex);
    }
    }
    

    PageContentViewController is the class where you are showing your data of pageViewController.

    Run your project and if everything is working fine, you will get your index value. PageIndex is the Integer value for getting the current index. Hope it will helps you.

    Thanks

    Mandeep Singh

提交回复
热议问题