I am trying to present a UIViewController from the Storyboard (no UINavigationController here)
When I start my app, I print out:
print("self.view.window.rootViewController : \(UIApplication.sharedApplication().windows.first?.rootViewController)")
print("self : \(self)")
Output:
self.view.window.rootViewController : Optional(<NewProject.MainViewController: 0x7f95d0d8bcc0>)
self : <NewProject.MainViewController: 0x7f95d0d8bcc0>
My MainViewController
is indeed the rootViewController
. Good!
Then I want to present another UIViewController
and I do:
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewControllerWithIdentifier("testViewController") as! TestViewController
presentViewController(vc, animated: true, completion: nil)
And I get an error:
Warning: Attempt to present <NewProject.testViewController: 0x7f95d0d92a20>
on <NewProject.MainViewController: 0x7f95d0d8bcc0> whose view
is not in the window hierarchy!
What's wrong? I'm trying to present a view controller from the root view controller.