2016-11-24 6 views
-3

私はinstantiateViewController:新しいビューを開こうと

ViewController.swift オープン新しいビューをしようとしている - > InAppBrowserController.swift

Main.storyboard - > InAppBrowserビュー&ストーリーボードイドを作る - > [OK]をクリックします。

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let nextViewController = storyboard.instantiateViewController(withIdentifier: "InAppBrowserView") as! InAppBrowserController 
self.present(nextViewController, animated: true, completion: nil) 

Blockquote fatal error: unexpectedly found nil while unwrapping an Optional value 2016-11-24 20:24:50.569000 GMK SWork[5920:2148780] fatal error: unexpectedly found nil while unwrapping an Optional value

問題は何ですか?ストーリーボードで

答えて

0

あなたがこの方法で得ることができる前にあなたは、のUIViewControllerの識別子を設定する必要があります。

let yourController = UIStoryboard.init(name: @"yourStoryboardName", bundle: nil).instantiateViewController(withIdentifier: "yourVCIdentifier") as? UIViewController 

は、識別子を設定することが重要である(私はあなたのコントローラが、このために見つからないと思います)

いずれにしても

enter image description here

あなたは特別なニーズを持っていない場合は、あなたとあなたのコントローラを発表/ストーリーボードとプッシュから直接「セグエ」を使用する必要があります。

self.performSegue(withIdentifier: "yourVCIdentifier", sender: self) 
+1

私はすでにそれを試しました しかし、それは私を助けてくれました。 ありがとうございます!〜 –

0
let storyBoard = UIStoryboard(name: "Main", bundle: nil) 
if let controller = storyBoard.instantiateViewController(withIdentifier: "InAppBrowserView") as? InAppBrowserController { 
    self.present(controller, animated: true, completion: nil) 
    } else { 
     print("Controller not found") 
    } 

上記のように、安全なコードを書くと、それはnilを返します。あなたはストーリーボードに識別子を追加し、他のビューコントローラに適切にクラスが割り当てられていることを確認してください。

関連する問題