0

I followed http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ for creating a PageViewController.

This tutorial contains : (code for Restart button)

- (IBAction)restartButton:(id)sender {
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers   direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}

When i tried for Next button like this:

- (IBAction)nextPageButton:(id)sender {
PageContentViewController *startingViewController = [self viewControllerAtIndex:+1];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers   direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}

but it fails, how to perform next page action with the UIButton that responds with the PageControl till last page.

iOS Dev
  • 23
  • 4
  • http://stackoverflow.com/questions/7208871/is-it-possible-to-turn-page-programmatically-in-uipageviewcontroller/39190174?noredirect=1#comment65723601_39190174 Latest answer can be helpful – Yogesh Lolusare Aug 29 '16 at 17:03

2 Answers2

0

That wont work because you are using +1, instead, try this:

//get current index of current page
DataViewController *theCurrentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger retreivedIndex = [self.modelController indexOfViewController:theCurrentViewController];

//check that current page isn't first page
if (retreivedIndex < 5){

    //get the page to go to
    DataViewController *targetPageViewController = [self.modelController viewControllerAtIndex:(retreivedIndex + 1) storyboard:self.storyboard];

    //put it(or them if in landscape view) in an array
    NSArray *theViewControllers = nil;    
    theViewControllers = [NSArray arrayWithObjects:targetPageViewController, nil];

    //add page view
    [self.pageViewController setViewControllers:theViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

}
Reedy
  • 1,866
  • 2
  • 20
  • 23
0
PageNumberToJump=2


-(void)buyAction
{

isFromBuy = YES;

    APPChildViewController *initialViewController = [self viewControllerAtIndex:PageNumberToJump];
    viewControllers = [NSArray arrayWithObject:initialViewController];
    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}

-(NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{

    if (isFromBuy)
    {
        isFromBuy = NO;
        return PageNumberToJump;
    }
    return 0;

}
Jagveer Singh
  • 2,258
  • 19
  • 34