gpt4 book ai didi

ios - UIPageViewController 上的奇数个页面

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:02 27 4
gpt4 key购买 nike

我在我的 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)’

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

当“书”的页数为奇数(例如 7 页)时,如何避免之前的异常?

最佳答案

我的修复方式是这样的。

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)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;
}

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

希望对您有所帮助。

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com