UIPageViewController在方向更改时抛出SIGABRT

时间:2012-04-19 00:41:39

标签: ios xcode 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;
}

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

嗯,你没有提供控制台的输出,这将是不错的。快速查看代码我猜你的一个控制器(下一个或上一个)是nil,因为你不能将nil插入NSArray(除了作为最后一个对象)之外它会抛出一个错误。

编辑嗯,我的猜测错了。错误消息是说您提供给它的UIViewControllers不支持页面控制器所需的方向。这是因为您的子UIViewControllers中有一个名为shouldRotateToInterfaceOrientation:的方法,并且它们(在这种情况下)为左侧格局返回no。

答案 2 :(得分: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;
}