2017-06-20 58 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

    非常感谢。它的工作原理与你之前的答案一样。非常感谢您的反馈。谢谢。 –