7
votes

The goal is to create a UIPageViewController that can only navigate forward. I am using a data source to provide the content for the UIPageViewController. The direction is set to UIPageViewControllerNavigationDirectionForward, the transition style is UIPageViewControllerTransitionStyleScroll.

The implementation of

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    // returns the next view controller
}

returns the next view controller, while the following should ensure navigating backwards is impossible

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    return nil;
}

Returning nil should indicate that navigation is not possible (as stated in the documentation). However, I am always possible to scroll back one page. Let's say I have 10 pages, I can scroll forward through all pages but at any page I can scroll back 1 page. (For example: at page 5 I can go back to page 4, at page 8 I can go back to page 7, and so on.)

I know I can avoid this by not using a data source and using the setViewControllers:direction:animated:completion: method, but I'd like to understand why my attempt is failing.

2

2 Answers

4
votes

This is the behavior you get when your pageViewController has its transition style set to scroll -- I'm not sure why, but it has something to do with a scroll view being inserted into the hierarchy somewhere (which I could see being allocated if I ran my project with Instruments turned on). If the transition is Page Curl, then you don't get any previous page being displayed if your return nil where you do.

So, I think you're stuck with using setViewControllers:direction:animated:completion: unless you want to switch to the Page Curl animation.

0
votes

Here is a simple solution, simply set isLeftScrollEnabled default value to false in the protocol: UIPageViewController with configurable scroll directions