ios – 在刷过最后一个视图控制器后,如何解除/弹出UIPageViewController?

前端之家收集整理的这篇文章主要介绍了ios – 在刷过最后一个视图控制器后,如何解除/弹出UIPageViewController?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在刷过最后一个视图控制器后,如何解除/弹出UIPageViewController?
基本上想要用图像制作一个教程样式的分页视图,并在用户从最后一页滑到“下一页”后解散.
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {

    NSUInteger index = [(EmailTutorialViewController *)viewController index];


    index++;

    if (index == 5) {
        [self.navigationController popViewControllerAnimated:YES]; // this doesn't do anything
        return nil;
    }

    return [self viewControllerAtIndex:index];
}

解决方法

这是我用过的简单解决方案:

– (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;

为索引返回空控制器== 5并添加此UIPageViewControllerDelegate方法

- (void)pageViewController:(UIPageViewController *)pageViewController 
willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
    EmailTutorialViewController *viewController = 
                [pendingViewControllers objectAtIndex:0];
    if ([viewController index] == 5) 
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

猜你在找的iOS相关文章