Load ViewController Swift - Black Screen

泪湿孤枕 提交于 2019-12-23 19:07:40

问题


Im trying to simply load a new ViewController and its associated xib when a button is clicked, but the screen becomes black after the new view is loaded. When the button is clicked the following method is called:

    let vc = MainViewController()
    self.showViewController(vc, sender: nil)

I am able to debug and see that we are jumping into the viewDidLoad method of the new "MainViewController" class, but the UI is not rendering and the screen is black. I have set the File's Owner of MainViewController.xib to the MainViewController.swift class, but nothing happens. super() is being called in the class as well. The only thing in MainViewController.xib is a MapView.


回答1:


Try this, your are missing name of xib...

 let vc = MainViewController(nibName: "MainViewController", bundle: nil) // Enter you nibname in this 
 self.showViewController(vc, sender: nil)

Thanks :)



来源:https://stackoverflow.com/questions/28555004/load-viewcontroller-swift-black-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!