title: Refresh a UIPageViewController
body: <p>I have a <code>UIPageViewController</code> (<code>&lt;UIPageViewControllerDataSource&gt;</code> delegate) that manages 3 <code>UIViewController</code>.
  To go from the second view to the third, i have to tap a button, otherwise the second view is the last visible page. Once on page 3, the user should be able to swipe to get back to 2, but not be able to swipe to return to 3 (the button is always necessary to get to page 3).
  This is part of the code:</p>
  
  <pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
      UIViewController *prevViewController = nil;
      if (viewController == self.P2ViewController) {
          prevViewController = self.P1ViewController;
      }
      if (viewController == self.P3ViewController) {
          [self pageViewController:pageViewController viewControllerAfterViewController:self.P2ViewController]; /*this doesn't work*/
          prevViewController = self.P2ViewController;
      }
      return prevViewController;
  }
  - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
      UIViewController *nextViewController = nil;
      if (viewController == self.P1ViewController) {
          nextViewController = self.P2ViewController;
      }
      if (viewController == self.P2ViewController) {
          nextViewController = nil;
      }
      return nextViewController;
  }
  </code></pre>
  
  <p>Then i have a custom <code>UIViewController</code> class where i have an IBAction and i pass the correct UIViewController with a static variable and a notification. Part of the code:</p>
  
  <pre><code>-(IBAction)goToPage:(NSNotification *)notification{
      /*some code*/
      [((UIPageViewController *)self.parentViewController) setViewControllers:viewControllersArray direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
  }
  </code></pre>
  
  <p>The first time i go from page 1 to 2, the second page is the last one. Then i tap the button and i go to the third page correctly with the animation (the "animated bug" in <code>UIPageViewController</code> works good for me). Then the third view is the last one and i can go back to the second view, but when i go back no <code>viewControllerAfterViewController:</code> method is called and i can still go to the third page.</p>
  
  <p>Instead, i want to go back to the second page leaving the second page as the last one again, deleting the third page from the cache every time i go back.
  I've tried with this code in my custom <code>UIViewController</code> class for the second page:</p>
  
  <pre><code>-(void)viewWillAppear:(BOOL)animated{
      [((UIPageViewController *)self.parentViewController) setViewControllers:@[myStaticViewController2] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
  }
  </code></pre>
  
  <p>but it only works the second time i try to move back or forth from that page. It's also useless calling again the <code>viewControllerAfterViewController</code> inside the <code>viewControllerBeforeViewController</code> like i did.
  I hope i was clear, i can't find a solution to this problem.</p>
  
  <p>Thanks in advance</p>