How can I add new pages to a UIPageViewController after the user has reached the last page?

依然范特西╮ 提交于 2019-12-04 04:21:41
ssloan

See here: Refresh UIPageViewController - reorder pages and add new pages

When you get your data back from the network, call setViewControllers: direction: animated: completion: and set the current view to the current one again. That forces it to re-call pageViewController:viewControllerAfterViewController:

ssloan's answer was part of the key, but in my case simply calling setViewControllers:direction:animated:completion: in the network operation completion block wasn't enough (due to some edge cases).

My solution was to store the most recent view controller for which pageViewController:viewControllerAfterViewController: returned nil (I called it endPage) and to create a method...

- (void)fixAndResetEndPage {
    if (self.endPage && self.endPage == self.currentPage) {
        [self.pageController setViewControllers:@[self.currentPage] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
        self.endPage = nil;
    }
}

...which I called whenever my NSMutableArray of content controllers was mutated (e.g., network operation completion) and in pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted: whenever completed was YES.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!