问题
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