简体   繁体   中英

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 and UINavigationController 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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM