2012-04-19 61 views
2

我有以下代码来显示杂志类型的应用程序。当应用程序旋转时,它运行此代码。我确信只有在旋转到支持的方向时才会运行它。当此函数返回时,应用程序将失败,并显示SIGABRT。没有其他迹象表明为什么。UIPageViewController在方向更改时抛出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; 
} 
+0

我升级到SDK5.1,现在我( “”, “”)因为未捕获的异常'NSInternalInconsistencyException',原因:'所有提供的视图控制器( “))必须支持未定义的界面方向(UIInterfaceOrientationLandscapeLeft)'_ – 2012-04-19 21:53:31

回答

0

那么你没有提供控制台的输出,这将是很好的。简单地看一下代码,我猜你的控制器(下一个或前一个)是零,并且由于不能将nil插入NSArray(除了最后一个对象),它会抛出一个错误。

编辑嗯,我的猜测是错误的。错误消息是说你给它的UIViewControllers不支持页面控制器需要的方向。这是因为您的子UIViewControllers中有一个名为shouldRotateToInterfaceOrientation:的方法,并且它们正在返回no(在本例中)为left横向。

+0

我添加了控制台输出,现在我已经升级了SDK的 – 2012-04-19 21:56:33

+0

@RyanH看到我更新的答案,并且在将来尝试始终包含这样的信息。 SIGABRT本身并没有告诉我们什么。 – borrrden 2012-04-19 23:33:12

1

唉,borrrden可能是对的。您的一个IBOutlets可能在您的XIB中缺失。确保你的所有IB都连接正确,如果问题仍然存在,请这么说。

+0

谢谢,但我的文件是编程方式不使用笔尖。 – 2012-04-19 21:55:39

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; 
}