0

I got 4 controllers inside my UIPageViewController. I start on the 1st controller. Then after notification received I open 4th controller programmatically. Like this:

[self setViewControllers:@[controller]
                       direction:UIPageViewControllerNavigationDirectionForward
                        animated:NO completion:^(BOOL finished)
         {
             if (finished) {
                 index.indexOfController = [controllers indexOfObject:controller];
                 [index centerTitle];
             }
         }];

When I start to swipe back, I can move only to 1st controller, not to 3rd. What is the reason? How to fix it?

Thanks.

Upd.

This is my before function

- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    NSInteger index = [self.controllers indexOfObject:viewController];

    index --;

    if (index < 0)
        return nil;
    else
        return self.controllers [index];
}

For some reason, class of view controller here is the class of the first controller. I thought, it should be 4th controller.

Eugene Trapeznikov
  • 3,220
  • 6
  • 47
  • 74
  • This is the best example of UIPageViewController http://stackoverflow.com/questions/8140545/how-to-add-an-array-of-pages-to-a-uipageviewcontroller-in-ios-5 – Bera Bhavin Mar 27 '17 at 18:52
  • What value are you returning for `viewControllerBefore` when you are showing the 4th controller? – DonMag Mar 27 '17 at 18:55
  • @DonMag please, see my update – Eugene Trapeznikov Mar 27 '17 at 19:00
  • @EugeneTrapeznikov - ok... You haven't shown much of your code, but it looks like you somewhere create an array of the ViewControllers you want to show? have you put a breakpoint there and checked the values of `self.controllers`, `index`, etc? Is `[self.controllers indexOfObject:viewController];` *really* finding the correct index? – DonMag Mar 27 '17 at 19:05
  • @DonMag Yes, indexofobject finding correct index, but object is the 1st controller while I swiping from 4th. Is it correct? – Eugene Trapeznikov Mar 27 '17 at 19:06
  • So... when you programmatically show the 4th controller, `viewControllerBeforeViewController` ***does*** return a valid ViewController object? Or is it returning `nil`? – DonMag Mar 27 '17 at 19:10
  • @DonMag viewControllerBeforeViewController doesn't call when I call setViewControllers. It calls only while swiping. – Eugene Trapeznikov Mar 27 '17 at 19:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139179/discussion-between-donmag-and-eugene-trapeznikov). – DonMag Mar 27 '17 at 19:15

0 Answers0