3

我已经UIPageViewController在我的项目中添加了一个用于创建演练屏幕的项目,但我似乎可以理解如何使用故事板使其工作。

首先我定义了两个数据源方法:viewControllerBeforeViewControllerviewControllerAfterViewController.

- (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];
}

有人能指出我正确的方向吗?

4

0 回答 0