2012-04-19 66 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; 
}