Search code examples
iosios5uikit

Turn page programmatically in UIPageViewController when using UIPageViewControllerDataSource?


I have an UIPageViewController and a class which conforms to UIPageViewControllerDataSource and manages the UIViewControllers which UIPageViewController displays. It all runs well when turning the pages is initiated by the user. But now I want to do that programmatically.

I've found that there is a very similar question here on SO which answers the question for a static amount of ViewControllers: Is it possible to Turn page programmatically in UIPageViewController?

But I'm unable to adapt the answers to the use of UIPageViewControllerDataSource. I was thinking that there must be something like:

- (void)setCurrentViewController:(UIViewController *)viewController

I suppose I'm just overlooking something here.


Solution

  • The Method mentioned in the answer ( setViewControllers:direction:animated:completion: ) sets the current view controller and is exactly what you need. With the first param you define the view controller(s), you want to display. Use one if you don't have a spine, if you book is left/right use two.