2

我有以下代码来显示杂志类型的应用程序。当应用程序旋转时,它会运行此代码。我确保它仅在旋转到支持的方向时运行。当此函数返回时,应用程序将失败并显示 SIGABRT。没有其他迹象表明原因。

我知道这是这个功能,因为当我删除它时,程序不会失败。

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
                   spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    //If portrait mode, change to single page view
    if(UIInterfaceOrientationIsPortrait(orientation)){
        UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
         NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
         [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

         self.pageViewController.doubleSided = NO;

        return UIPageViewControllerSpineLocationMin;
    //If landscape mode, change to double page view    
    }else{
        //Get current view 
        UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];

        //Create an array to store, views
        NSArray *viewControllers = nil;

         NSUInteger currentIndex = self.currentPage;

        //Conditional to check if needs page before or after
         if(currentIndex == 1 || currentIndex %2 == 1){
             UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
             viewControllers = [NSArray arrayWithObjects:currentViewController,nextViewController, nil];
         }else{
             UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
             viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
         }

        [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
        return UIPageViewControllerSpineLocationMid;

    }
    //return UIPageViewControllerSpineLocationMid;
}
4

3 回答 3

1

唉,borrrden 可能是对的。您的 XIB 中可能缺少您的 IBOutlets 之一。确保您的所有 IB 都正确连接,如果问题仍然存在,请说出来。

于 2012-04-19T01:24:06.427 回答
0

好吧,您没有提供控制台的输出,这很好。快速浏览一下代码,我猜你的一个控制器(下一个或上一个)是 nil,并且由于你不能将 nil 插入到 NSArray 中(除了作为最后一个对象),它会引发错误。

编辑好吧,我的猜测是错误的。错误消息是说你给它的 UIViewControllers 不支持页面控制器需要的方向。这是因为您在您的子 UIViewControllers 中调用了一个方法shouldRotateToInterfaceOrientation:,并且它们没有返回(在这种情况下)左景观。

于 2012-04-19T01:20:41.330 回答
0

我遇到了同样的错误

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'All provided view controllers ((
    "<ContentViewController: 0x6a7eac0>",
    "<ContentViewController: 0x6d89f10>"
)) must support the pending interface orientation (UIInterfaceOrientationLandscapeLeft)'

将以下内容添加到我的 PageModel 类中,其中页面布局的设计对我有用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
于 2013-03-07T09:08:46.070 回答