2014-11-03 102 views
0

我試圖讓彈出窗口出現在按下按鈕的ios 8中,但應用程序在按下按鈕時崩潰。我已經設置了正確的所有故事板,並使用斷點我決定在這條線,導致即使這是爲了顯示在酥料餅的視圖控制器是FirstViewController類的問題:當出現彈出窗口時應用程序崩潰

UIViewController *vc = destNav.viewControllers.firstObject; 

這是崩潰:

***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [SecondViewController viewControllers]:無法識別的選擇發送到實例0x1446ea3a0'


這是休息我的代碼從該部分:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
// Assuming you've hooked this all up in a Storyboard with a popover presentation style 
if ([segue.identifier isEqualToString:@"popover"]) { 
    UINavigationController *destNav = segue.destinationViewController; 
    FirstViewController *vc = destNav.viewControllers.firstObject; 

    // This is the important part 
    UIPopoverPresentationController *popPC = destNav.popoverPresentationController; 
    popPC.delegate = self; 
} 
} 

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { 
return UIModalPresentationNone; 
} 
+0

最有可能的'destNav.viewControllers.firstObject'是'nil'。你可以在你的問題中發佈錯誤消息嗎? – 2014-11-03 21:29:09

+0

發佈有關崩潰的詳細信息。究竟是哪條線崩潰?什麼是崩潰的完整和準確的錯誤信息? – rmaddy 2014-11-04 00:59:15

+0

我已將錯誤消息添加到問題中,並且確切的線路是在最初的問題中。 – newbie 2014-11-04 07:25:25

回答

0

我的工作了!遺憾的是,我張貼這種比較晚

您只需排除線

FirstViewController *vc = destNav.viewControllers.firstObject; 

即使所有的教程顯示此行

-1

嘗試鑄造您的視圖控制器是這樣的:

FirstViewController *vc = (FirstViewController *)destNav.viewControllers.firstObject; 
+0

1)指針轉換隻用於編譯時,並且在運行時不起作用。 2)這個轉換是不必要的,因爲'firstObject'返回一個'id',它可以在不投射的情況下分配給任何指針類型。 – rmaddy 2014-11-04 01:01:25

相關問題