iphone - 如何在 UIPageViewController 中设置第一页

标签 iphone objective-c ios ipad uipageviewcontroller

当用户位于 UIPageViewController 的第一页并尝试返回时,我只返回 nil。在 iOS 5 中这工作正常。它导致 iOS 6 崩溃。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The number of view controllers provided (0) doesn't match the number required (1) for the requested transition'

这是我的代码。当返回 contentViewController 而不是 nil 时,它工作正常。我应该用什么代替 nil

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController 
  viewControllerBeforeViewController:(UIViewController *)viewController {

    contentViewController = [[ContentViewController_iPhone alloc] init];

    int currentIndex = [self.modelArray indexOfObject:[(ContentViewController_iPhone *)viewController labelContents]];

    if ((currentIndex == 0) || (currentIndex == NSNotFound)) {

        //if on the first page, can't go back
        return nil;

     }

    contentViewController.labelContents = [self.modelArray objectAtIndex:currentIndex - 1];

    return contentViewController;

}

最佳答案

我有同样的问题,发现只有当我将 pageviewcontrollers gestureRecognizers 的代表更改为我自己的 Controller 时才会发生(如果您想在用户点击页面上的某些区域时取消分页,通常会这样做,例如按钮)。

对我来说,不对 iOS 6 进行这种重新分配是有效的。这很好,因为 iOS 处理触摸有点不同。页面上的按钮或您自己的手势识别器在 iOS 6 下可以正常工作,因为它们具有优先权并且会自动取消分页。

希望对您有所帮助。

关于iphone - 如何在 UIPageViewController 中设置第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786641/

相关文章:

objective-c - iOS 新手。预期的表达错误?

ios - 在 iOS 上使用智能卡进行 TLS 身份验证

c++ - 使用 C++ 编写的算法实时处理数据

ios - 使用 GoogleService-Info.plist 配置适用于 iOS 应用程序的 Google 分析时出错

ios - 如何使用 SFSafariViewController 从 iOS Safari 应用程序读取 Cookie

ios - 当我在真实设备 iOS 中运行它时应用程序崩溃

Objective-C语法问题

iPhone 开发者 : Swipe a UITableCell

iphone - MapView 以用户坐标为中心缩放

objective-c - Mac 10.6 及更高版本的可用启动磁盘空间错误