我找不到将视图控制器作为页面的 PageViewController 的工作示例。
我只需要两个水平视图控制器:viewcontroller1 和 viewcontroller2。
这是我的viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationVertical options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
controller1 = [storyboard instantiateViewControllerWithIdentifier:@"first"];
controller2 = [storyboard instantiateViewControllerWithIdentifier:@"second"];
viewControllers = [NSArray arrayWithObjects:controller1, nil];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
return controller1;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
return controller2;
}
问题是,在滑动第二个视图后,它就消失了。一些帮助理解 PageViewController 会非常好。
提前致谢