菜鸟教程小白 发表于 2022-12-11 17:56:01

ios - UIPageViewController 有条件地转到下一页


                                            <p><p>我有 <code>UIPageViewController</code>,我可以使用下面的委托(delegate)方法进入下一页和上一页。</p>

<pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    if (])
       return nil;

    if(_counter &lt; 1) {
       return nil;
    }

    self.view.backgroundColor = ;
    return ;
}
</code></pre>

<p><strong>编辑:</strong></p>

<pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    //NSLog(@&#34;Child controller count= %lu&#34;,(unsigned long)pageViewController.childViewControllers.count);

    if (])
      return nil;

    if(])
    {
      TableViewController *viewController1 = (TableViewController*) viewController;
      if (viewController1.dataArr.count &lt; 5) {
            return nil;
      }
    }

    return ;
}
</code></pre>

<p>现在如果满足某些条件,我想转到下一页。喜欢最后一页<strong>viewController.isCheck == true</strong>。</p>

<p>我怎样才能做到这一点?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以将该条件添加到现有 if 之一,如果条件未得到验证,则返回 nil。比如:</p>

<pre><code>- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    if (] || ((YourViewControllerClass *)viewController).isCheck == false)
       return nil;

    return ;
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIPageViewController 有条件地转到下一页,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40213526/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40213526/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIPageViewController 有条件地转到下一页