一次返回nil后不调用UIPageViewController viewControllerAfterViewController [英] UIPageViewController viewControllerAfterViewController not called after once returned nil

查看:177
本文介绍了一次返回nil后不调用UIPageViewController viewControllerAfterViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在每个步骤上通过验证来实现UIPageViewController.我的代码未经验证即可正常工作,因此所有带有页面的操作似乎都正确完成了.这是我的代码:

I'm trying to implement UIPageViewController with validation on every step. My code was working fine without validation, so everything with pages seems to be done right. This is my code:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    int index = [(MyViewController *) viewController index];
    index--;
    return [_viewModel viewControllerAtIndex:index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    BOOL isDataValid = [(MyViewController *) viewController validateData];
    if (isDataValid) {
        int index = [(MyViewController *) viewController index];
        index++;
        return [_viewModel viewControllerAtIndex:index];
    }
    return nil;
}

我的问题是,当显示第1步时,调用viewControllerAfterViewController来准备第2步,但是由于第2步无效(用户没有机会输入数据),因此返回nil.我希望UIPageViewController每次用户尝试滑动到下一个屏幕时都调用viewControllerAfterViewController,并且在收到nil后不放弃.可以吗?

My problem is that when step 1 is shown, viewControllerAfterViewController is called to prepare step 2, but because step 2 cannot be valid (user didn't have chance to input data) so it is returning nil. I would like UIPageViewController to call viewControllerAfterViewController every time user tries to swipe to the next screen and not give up after receiving a nil. Is it doable?

推荐答案

UIPageViewController具有基础缓存.您可以使用

UIPageViewController has an underlying cache. You can reset it with

pageViewController.dataSource = nil;
pageViewController.dataSource = self;

当您所在的页面生效后,您可以调用此名称.

You can call this once the page you are on becomes valid.

这篇关于一次返回nil后不调用UIPageViewController viewControllerAfterViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆