我有UIPageViewController,可以使用以下委托方法转到下一页和上一页。

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    if ([viewController isKindOfClass:[PageController class]])
       return nil;

    if(_counter < 1) {
       return nil;
    }

    self.view.backgroundColor = [UIColor lightGrayColor];
    return [self.storyboard instantiateViewControllerWithIdentifier:@"memoTable"];
}

编辑:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    //NSLog(@"Child controller count  = %lu",(unsigned long)pageViewController.childViewControllers.count);

    if ([viewController isKindOfClass:[PageController class]])
        return nil;

    if([viewController isKindOfClass:[TableViewController class]])
    {
        TableViewController *viewController1 = (TableViewController*) viewController;
        if (viewController1.dataArr.count < 5) {
            return nil;
        }
    }

    return [self.storyboard instantiateViewControllerWithIdentifier:@"pageView"];
}

现在,如果满足某些条件,我想转到下一页。像最后一页一样 viewController.isCheck == true

我该如何实现?

最佳答案

您可以将该条件添加到现有的if之一,如果条件未经验证,则返回nil。就像是:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    if ([viewController isKindOfClass:[PageController class]] || ((YourViewControllerClass *)viewController).isCheck == false)
       return nil;

    return [self.storyboard instantiateViewControllerWithIdentifier:@"pageView"];
}

关于ios - UIPageViewController有条件地转到下一页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40213526/

10-13 09:27