Reputation: 3336
On a UIViewController instantiated by a UITabBarController, when I run the following code,
let destination = self.storyboard?.instantiateViewControllerWithIdentifier("test")
self.navigationController!.pushViewController(destination!, animated: true)
navigationController
return nil. How can I get navigationController
instance to push a view controller?
Upvotes: 3
Views: 14248
Reputation: 425
https://stackoverflow.com/a/32959896/3810914
Exactly. If you did, the error would be resolved
Upvotes: 0
Reputation: 3336
As @Paulw11 said, what was missing was embed the UIViewController
in a navigation controller. To do that, drag-and-drop a Navigation Controller
to the Storyboard and CTRL + drag from that Navigation Controller
to the UIViewController
, chosing the relationship root view controller
.
Upvotes: 7
Reputation: 114875
Your source UIViewController
instance needs to be embedded in a UINavigationController
in the storyboard scene in order to provide a navigation controller instance to push to.
Upvotes: 1