2017-06-20 3 views
0

ログイン後にVCを表示しようとしていますが、ログインが成功した後はVCが黒くなります。デモンストレーションはhereで、同じ画像があります。私はstackoverflow上の記事を発見したが、それらのいずれかが私を助けていない。 enter image description hereenter image description hereenter image description hereenter image description hereVCを提示する際の問題、画面が黒くなる

+0

'ALMainController()'は 'ALMainController.init'に等しく、「ALMainController.initTheOneSetWithAllTheOutletsAndConstraintsInTheStoryboard」には等しくありません。 https://stackoverflow.com/questions/24035984/instantiate-and-present-a-viewcontroller-in-swift – Larme

答えて

0

enter image description hereは、このコード試してみてください。

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc: ALMainController = storyboard.instantiateViewController(withIdentifier: "ALMainController") as! ALMainController 

    self.present(vc, animated: true, completion: nil) 

をそれとも、これを使用することができます:

let firstPage = self.storyboard?.instantiateViewController(withIdentifier: "ALMainController")as! ALMainController 
    let appDelegate = UIApplication.shared.delegate 
    appDelegate?.window??.rootViewController = firstPage 

はどちらも動作するはずです。

あなたのストーリーボードIDに「ALMainController」と書いてください。

enter image description here

それが働いていた場合、私に教えてください。 :)

0

問題は、あなたがALMainControllerクラスを初期化しているということです。

しかし、これはストーリーボードからのビューを読み込みません。それを適切に行い、そのコントローラを提示するには2つの方法があります。作成することにより、 "ALMainController"

let storyboard = UIStoryboard(name: "Main", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "ALMainController")
self.present(controller, animated: true, completion: nil)

  • を:次のようなものを実行して、コードで

    1. は、このコントローラは次のように識別子を有していることを考えるとストーリーボードのSegueは、 "Login Controller"から "ALMainController"に向かっています。とができます以下の

    self.performSegue(withIdentifier: "goToMain", sender: self)

    希望のようなものをやって、あなたのコードでそれを呼び出す:あなたはそれが(「goToMain」EX)の識別子をセグエ与えます!

  • +0

    ありがとうございます。それはあなたの前の答えと同じです。あなたのフィードバックをたくさん感謝します。ありがとう。 –

    関連する問題