UIPageViewController有条件转到下一页

时间:2016-10-24 08:09:06

标签: ios objective-c uipageviewcontroller

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

我怎样才能做到这一点?

4 个答案:

答案 0 :(得分:0)

您可以将该条件添加到其中一个现有ifs中,如果未验证该条件,则返回nil。类似的东西:

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

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

答案 1 :(得分:0)

只需检查您实例化的视图控制器,然后再以pageViewController:viewControllerAfterViewController方法返回。

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

    let pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"pageView"];
    if (pageViewController.isCheck)
       return pageViewController;
    else return nil;
}

答案 2 :(得分:0)

我的第二个猜测是你应该在导航之前尝试在private static void Connect<TConnection, TCommand>(ExportManifest m_settings, Func<string, TConnection> createConnection, Func<string, TConnection, TCommand> createCommand) where TConnection : IDbConnection where TCommand : IDbCommand { using (TConnection mySqlConnection = createConnection(m_Settings.TargetData.ConnectionString)) { TCommand mySqlCommand = createCommand(Program.GetCommandTextTemplate(m_settings), mySqlConnection); PrepareSqlCommand(mySqlConnection, mySqlCommand, m_settings); } } private static void PrepareSqlCommand<TConnection, TCommand>(TConnection sqlConnection, TCommand sqlCommand, ExportManifest m_settings) where TConnection : IDbConnection where TCommand : IDbCommand { sqlConnection.Open(); } 中实例化你需要的所有视图控制器。

UIPageViewController

分配数组中需要的所有视图控制器

UIViewController* memoViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"memoTable"];
UIViewController* pageViewContentController = [self.storyboard instantiateViewControllerWithIdentifier:@"pageView"];

使用索引来跟踪当前页面的位置

NSArray* reservedViewControllers = @[memoViewController, pageViewController];

然后,您可以在UIPageViewControllerDataSource函数中轻松地在视图控制器之间进行迭代。

int currentIndex = 0;

答案 3 :(得分:0)

根据您的问题,您应该使用滚动视图来实现此目的..设置滚动视图的内容大小,并将内容偏移量提供给您桌面上的内容... 供您参考:

查看链接: https://github.com/cwRichardKim/RKSwipeBetweenViewControllers https://github.com/nicklockwood/SwipeView