2017-02-24 59 views
0

我怎麼可以這樣做時,他/她輕叩「好」按鈕,提醒用戶被帶到一個自定義視圖控制器?無法執行賽格瑞

我有一個主控制器 - >導航控制器 - >第二視圖控制器。

主視圖控制器具有第二視圖控制器上獲取生成警報一個賽格瑞「mainStoryBoard」 。

這是我

let alertController = UIAlertController(title: "title", message: "message",  preferredStyle: .alert) 
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { action 
    in self.performSegue(withIdentifier: "mainStoryBoard", sender: self) 
})) 

present(alertController, animated: true, completion: nil) 
return 

我得到的錯誤是:

終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',理由是:「接收器()沒有SEGUE與標識符'mainStoryBoard'

我已經設置標識符爲'mainStoryBoard',仍然沒有運氣。

任何指導將不勝感激。

+1

您發佈的代碼有哪些問題? – rmaddy

+0

@rmaddy我越來越 - 終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:'接收器()沒有與標識符'mainStoryBoard'''' – rob

+0

確保你已經給了segue標識符正好等於「mainStoryBoard」 – MikeG

回答

0

感謝@ MikeG的指導下我能得到它的工作。

問題是我創建了從0​​到second view controller的segue。

解決方案

創建一個從second view controller一個seguemain view controller,如果你有一個navigation controller,創建從second view controllernavigation controller的SEGUE。

代碼保持不變。

0

你是如何加載你的主視圖控制器?嘗試使用instantiateviewcontrollerwithidentifier而不是alloc init來實例化。如果你正面臨這個問題,那就試着清理這個項目並運行。