1

I use a UIPageViewController for two view controllers. In the first view controller I have a 'NEXT' button to go to the second view controller. My question is: How can I wire it up?

In my first and second view controllers I do not have code yet. However, in my RootViewController I have this code:

- (void)viewDidLoad {
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController2"];
    self.pageViewController.dataSource = self;
    SeekerRegistrasiViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"seeker1"];
    Seeker2RegistrasiViewController *pvc;
    self.array =[NSArray arrayWithObjects:tvc, pvc, nil];
    [self.pageViewController setViewControllers:self.array direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -60);
    self.pageViewController.view.backgroundColor = [UIColor clearColor];
    [self addChildViewController:pageViewController];
    [self.view addSubview:pageViewController.view];
    [self.pageViewController didMoveToParentViewController:self];
}

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
    if ([viewController isKindOfClass:[Seeker2RegistrasiViewController class]]) {
        SeekerRegistrasiViewController *pvc = [self.storyboard instantiateViewControllerWithIdentifier:@"seeker1"];
        return  pvc;
    }
    else return nil;
}



-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
    if ([viewController isKindOfClass:[SeekerRegistrasiViewController class]]) {
        Seeker2RegistrasiViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"seeker2"];
        return tvc;
    }
    else return nil;
}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
    return 2;
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
    return 0;
}

I would appreciate any help that would guide me in the right direction.

Amadeus Sanchez
  • 2,375
  • 2
  • 25
  • 31
  • Do you also want the default swipe control provided by the UIPageViewcontroller ? – Ratul Sharker Nov 26 '15 at 17:00
  • sure, can swipe and can use button next in first VC. now already can swipe, but i really need button work . – Muhammad Yusuf Nov 26 '15 at 18:14
  • actually apple does not provide such direct api, consult [this](http://stackoverflow.com/questions/13633059/uipageviewcontroller-how-do-i-correctly-jump-to-a-specific-page-without-messing) – Ratul Sharker Nov 26 '15 at 18:38

1 Answers1

-1

You can do it using setViewControllers:direction:animated:completion:. Look at this answer: Is it possible to Turn page programmatically in UIPageViewController?

You basically set again all the view controllers (already switched), define a direction (which the animation will use, for example, UIPageViewControllerNavigationDirectionForward), use YES for animated and a completion block for processing afterwards (like updating the currentPage index you manage).

Community
  • 1
  • 1
Alejandro Iván
  • 3,969
  • 1
  • 21
  • 30