• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIPageViewController 上的奇数页数

[复制链接]
菜鸟教程小白 发表于 2022-12-12 20:48:34 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我已经在我的 iPad 应用程序中实现了 UIPageViewController。但是,当 iPad 处于纵向时,您可以看到所有页面,但是当 iPad 处于横向时,您看不到最后一页,如果您在纵向的最后一页并更改为横向,则应用程序会崩溃以下错误:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘The >number of provided view controllers (1) doesn’t match the number required (2) for the >requested spine location (UIPageViewControllerSpineLocationMid)’

因为它需要两页,而只有一页。

当“书”的页数为奇数(例如 7 页)时,我该怎么做才能避免前面的异常?



Best Answer-推荐答案


我修的方法是这样的。

- (UIViewController *)pageViewControllerUIPageViewController *)pageViewController viewControllerAfterViewControllerUIViewController *)viewController {
    DSBookletPageViewController *currentVC = (DSBookletPageViewController *)viewController;
    NSUInteger currentIndex = [currentVC index];

    if(currentIndex >= self.modelArray.count-1) {
        if (currentIndex %2 == 0 && !isPortrait) {
            //return an empty one
            DSBookletPageViewController *newVC = [[DSBookletPageViewController alloc] init];

            [newVC setIndex:currentIndex+1];

            return newVC;
        } else {
            return nil;
        }
    }

    currentIndex ++;

    UIImage *currentPage = [self.modelArray objectAtIndex:currentIndex];
    DSBookletPageViewController *newVC = [[DSBookletPageViewController alloc] initWithImage:currentPage andOrientation:isPortrait];
    [newVC setIndex:currentIndex];

    return newVC;
}

我基本上检查我是否在数组的末尾,或者超出它,因为我正在向我的模型数组之外的 UIPageViewController 添加另一个页面。如果我在那里,并且当前索引是偶数并且我们不是纵向的,那么我添加页面,如果不是,那么我返回 nil。

希望对你有帮助。

关于ios - UIPageViewController 上的奇数页数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10582934/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap