我试图从Storyboard呈现一个UIViewController(这里没有UINavigationController)
当我启动我的应用时,我打印出来:
print("self.view.window.rootViewController : \(UIApplication.sharedApplication().windows.first?.rootViewController)")
print("self : \(self)")
输出:
self.view.window.rootViewController : Optional(<NewProject.MainViewController: 0x7f95d0d8bcc0>)
self : <NewProject.MainViewController: 0x7f95d0d8bcc0>
我的MainViewController
确实是rootViewController
。好!
然后我想提出另一个UIViewController
,我做:
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewControllerWithIdentifier("testViewController") as! TestViewController
presentViewController(vc, animated: true, completion: nil)
我收到错误:
Warning: Attempt to present <NewProject.testViewController: 0x7f95d0d92a20>
on <NewProject.MainViewController: 0x7f95d0d8bcc0> whose view
is not in the window hierarchy!
怎么了?我正试图从根视图控制器中呈现一个视图控制器。