我在项目中添加了一个UIPageViewController
来创建漫游屏幕,但我似乎可以理解如何使用故事板使其工作。
首先,我定义了两种数据源方法:viewControllerBeforeViewController
和viewControllerAfterViewController
。
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(WalktroughScreenPageViewController *)viewController index];
if (index == 0) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(WalktroughScreenPageViewController *)viewController index];
index++;
if (index == 3) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (WalktroughScreenPageViewController *)viewControllerAtIndex:(NSUInteger)index {
WalktroughScreenPageViewController *childViewController = [[WalktroughScreenPageViewController alloc] init];
childViewController.index = index;
return childViewController;
}
另外,为了显示底部的点,我添加了这两种方法:
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
我能理解的是如何在ViewDidLoad
中进行设置。我试过类似这样的东西给了我一个EXC_BAD_ACCESS
错误:
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataSource = self;
WalktroughScreenPageViewController *ic = [self viewControllerAtIndex:0];
[self setViewControllers:@[ic] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
有人能指出我正确的方向吗?