在每次翻页后调用方法调用UIPageViewController

时间:2017-01-18 17:47:40

标签: ios objective-c uipageviewcontroller

最初我认为这是一件非常简单的事情,但看起来并非如此。每当我的UIPageViewController中发生页面翻转时,我都需要向我的服务器发出一个简单的GET请求。我已尝试将方法用于以下方法进行服务器调用:

1

但是这些方法在每次翻页后都不会被一致地调用,因为UIPageViewController试图维护一个viewcontrollers的缓存。这个问题有解决方法吗?

1 个答案:

答案 0 :(得分:4)

您应该实施UIPageViewControllerDelegate方法

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
    if (finished) {
       // in case you are sure that you shows only YourViewController 
       YourViewController *vc = (YourViewController *)pageViewController.viewControllers.lastObject;
       // decide what is the index of the controller based on your own logic and do what you want with it 
    }
}

希望它有所帮助!