Search code examples
iosobjective-cuipageviewcontroller

UIPageViewController update number of pages


Hey guys I was looking to see if anyone knew how to update the number of pages in a UIPageViewController

A UIPageViewController has the method

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
    return count;
}

but that is called right at the beginning and there is no way to update it. With a table view you can call [tableView reloadData]

Does anyone know how to "reload" the data for a UIPageViewController?

Thanks guys


Solution

  • Use the UIPageViewController's setViewControllers method:

    - (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers 
                 direction:(UIPageViewControllerNavigationDirection)direction 
                 animated:(BOOL)animated 
                 completion:(void (^)(BOOL finished))completion;
    

    Call this method on the UIPageViewController, and pass it the view controller you would like to present.