Stephen Fox
Stephen Fox

Reputation: 14470

How to transition to a UINavigationController from a UIViewController

I am trying to transition (modal) via segue to a UINavigationController from a UIViewController. My UIViewController andUINavigationController are in interface builder.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    self.performSegueWithIdentifier("showNavController", sender: self)
}

However it keeps giving me a warning: Warning: Attempt to present <UINavigationController: 0x14d5095e0> on <Test.ViewController: 0x14d60d9d0> whose view is not in the window hierarchy!

Upvotes: 0

Views: 303

Answers (2)

rakeshbs
rakeshbs

Reputation: 24572

Why are you calling performSegueWithIdentifier inside prepareForSegue?
That is what is causing the error. You don't have to call the performSegueWithIdentifier again.

performSegueWithIdentifier is used to perform a segue operation. prepareForSegue is called after you call performSegueWithIdentifier function and before the segue transition happens.

Upvotes: 2

pnavk
pnavk

Reputation: 4630

You need to define a root view relationship for your Navigation Controller, otherwise it has nothing to display.

A navigation controller is a container view controller—that is, it embeds the content of other view controllers inside of itself.

Every navigation stack must have at least one view controller to act as the root.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html

Upvotes: 0

Related Questions