2

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

Fatal Dizz
  • 57
  • 1
  • 8
  • do you mean after switch the content view controller of pageViewController, then reload the content view controller's data? – aircraft May 01 '17 at 01:13

1 Answers1

2

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.

nathangitter
  • 9,607
  • 3
  • 33
  • 42
  • When I call that method it throws an exception and says: The number of view controllers provided (2) doesn't match the number required (1) for the requested transition – Fatal Dizz May 01 '17 at 00:21
  • You're right — looks like you should only pass a single view controller in that array. Have you seen this question? http://stackoverflow.com/q/15325891/6658553 – nathangitter May 01 '17 at 00:28
  • 1
    Okay thank you I just had to call that method with 1 and then let the methods for the previous and next view controller to handle that. Thanks! – Fatal Dizz May 01 '17 at 00:33
  • If my answer worked for you, feel free to mark it as accepted so others can benefit if they have the same issue in the future! – nathangitter May 01 '17 at 00:35