2017-06-20 82 views
0

我想在用戶登錄後呈現VC,但登錄成功後VC變黑。示範發生的事情是here並且有相同的圖像。我在這裏找到了關於stackoverflow的文章,但其中任何一個都沒有幫助我。 enter image description hereenter image description hereenter image description hereenter image description hereenter image description here呈現VC的問題,屏幕變黑

+0

'ALMainController()'等於'ALMainController.init',而不是「ALMainController.initTheOneSetWithAllTheOutletsAndConstraintsInTheStoryboard」。檢查:https://stackoverflow.com/questions/24035984/instantiate-and-present-a-viewcontroller-in-swift – Larme

回答

0

試試這個代碼:

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類。

但是,這不會從故事板加載您的視圖。有兩種方法可以正確地執行該操作並顯示該控制器。

  1. 在通過執行類似下面的代碼,因爲此控制器有一個標識符,如: 「ALMainController」

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

  • 通過創建在從「登錄控制器」開始走向「ALMainController」的故事板中搜尋。你給Segue公司的標識符(EX:「goToMain」),並調用在你的代碼做類似下面
  • self.performSegue(withIdentifier: "goToMain", sender: self)

    希望幫助!

    +0

    非常感謝。它的工作原理與你之前的答案一樣。非常感謝您的反饋。謝謝。 –