I have an UIPageViewController
and a class which conforms to UIPageViewControllerDataSource
and manages the UIViewControllers which UIPageViewContr
I've created a easy project with that functionality:
https://github.com/delarcomarta/AMPageViewController
Hope this can help you.
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.
Old question but the following implementation calls delegate and dataSource methods for turning to previous or next page (But doesn't check if delegate or dataSource is set):
- (IBAction)navigateReverse:(id)sender
{
UIViewController *controller = [self.dataSource pageViewController:self viewControllerBeforeViewController:self.designViewControllers[self.currentIndex]];
if (!controller)
{
return;
}
NSArray *newViewControllers = @[controller];
NSArray *previousViewControllers = self.viewControllers;
__weak __typeof(self) weakSelf = self;
[self.delegate pageViewController:self willTransitionToViewControllers:newViewControllers];
[self setViewControllers:newViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
[weakSelf.delegate pageViewController:weakSelf didFinishAnimating:finished previousViewControllers:previousViewControllers transitionCompleted:finished];
}];
}
- (IBAction)navigateForward:(id)sender
{
UIViewController *controller = [self.dataSource pageViewController:self viewControllerAfterViewController:self.designViewControllers[self.currentIndex]];
if (!controller)
{
return;
}
NSArray *newViewControllers = @[controller];
NSArray *previousViewControllers = self.viewControllers;
__weak __typeof(self) weakSelf = self;
[self.delegate pageViewController:self willTransitionToViewControllers:newViewControllers];
[self setViewControllers:newViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
[weakSelf.delegate pageViewController:weakSelf didFinishAnimating:finished previousViewControllers:previousViewControllers transitionCompleted:finished];
}];
}