我正在尝试转移到另一个ViewController,但它给了我黑屏!有我的代码:
if (content == nil) {
let sec: testViewController = testViewController(nibName: nil, bundle: nil)
self.present(sec, animated: true, completion: nil)
}
在故事板中
答案 0 :(得分:1)
从主故事板中将Storyboard ID提供给testViewController。
if content == nil {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let sec: testViewController = storyboard.instantiateViewController(withIdentifier: "testViewController") as! testViewController
self.present(sec, animated: true, completion: nil)
}
答案 1 :(得分:1)
在Storborad中提供故事板ID ex - > testViewControllerId并检查UseStoryboard Id
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let testController = storyboard.instantiateViewController(withIdentifier :"testViewControllerId") as! testViewController
self.present(testController, animated: true)
答案 2 :(得分:0)
您只想尝试其他方式以编程方式显示目标ViewController。试试这个,
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let myViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("<myViewControllerRestorationID>") //if you have the restoration ID, otherwise use 'ModalViewController'
self.presentViewController(myViewController, animated: true, completion: nil)