Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So I ran into the same problem as you where I needed to be able to 'jump' to a page and then found the 'order messed up' when I gestured back a page. As far as I have been able to tell, the page view controller is definitely caching the view controllers and when you 'jump' to a page you have to specify the direction: forward or reverse. It then assumes that the new view controller is a 'neighbor' to the previous view controller and hence automagically presents the previous view controller when you gesture back. I found that this only happens when you are using the <code>UIPageViewControllerTransitionStyleScroll</code> and not <code>UIPageViewControllerTransitionStylePageCurl</code>. The page curl style apparently does not do the same caching since if you 'jump' to a page and then gesture back it delivers the <code>pageViewController:viewController(Before/After)ViewController:</code> message to the data source enabling you to provide the correct neighbor view controller.</p> <p>Solution: When performing a 'jump' to page you can first jump to the neighbor page to the page (<code>animated:NO</code>) you are jumping to and then in the completion block of that jump, jump to the desired page. This will update the cache such that when you gesture back, the correct neighbor page will be displayed. The downside is that you will need to create two view controllers; the one you are jumping to and the one that should be displayed after gesturing back.</p> <p>Here is the code to a category that I wrote for <code>UIPageViewController</code>:</p> <pre><code>@implementation UIPageViewController (Additions) - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction invalidateCache:(BOOL)invalidateCache animated:(BOOL)animated completion:(void (^)(BOOL finished))completion { NSArray *vcs = viewControllers; __weak UIPageViewController *mySelf = self; if (invalidateCache &amp;&amp; self.transitionStyle == UIPageViewControllerTransitionStyleScroll) { UIViewController *neighborViewController = (direction == UIPageViewControllerNavigationDirectionForward ? [self.dataSource pageViewController:self viewControllerBeforeViewController:viewControllers[0]] : [self.dataSource pageViewController:self viewControllerAfterViewController:viewControllers[0]]); [self setViewControllers:@[neighborViewController] direction:direction animated:NO completion:^(BOOL finished) { [mySelf setViewControllers:vcs direction:direction animated:animated completion:completion]; }]; } else { [mySelf setViewControllers:vcs direction:direction animated:animated completion:completion]; } } @end </code></pre> <p>What you can do to test this is create a new 'Page-Based Application' and add a 'goto' button that will 'jump' to a certain calendar month and then gesture back. Be sure to set the transition style to scroll.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload