我为两个视图控制器使用UIPageViewController。在第一个视图控制器中,我有一个' NEXT'按钮转到第二个视图控制器。我的问题是:我如何连线?
在我的第一个和第二个视图控制器中,我还没有代码。但是,在我的RootViewController中,我有这个代码:
- (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;
}
我将非常感谢能够指导我朝着正确方向前进的任何帮助。
答案 0 :(得分:0)
您可以使用setViewControllers:direction:animated:completion:
执行此操作。
看看这个答案:Is it possible to Turn page programmatically in UIPageViewController?
您基本上再次设置所有视图控制器(已切换),定义方向(动画将使用的方向,例如UIPageViewControllerNavigationDirectionForward
),使用YES
进行动画处理,使用完成块进行处理之后(比如更新您管理的currentPage
索引)。