简体   繁体   中英

Swift ios not sure how to add navigation bar to VC in storyboard when using storyboard id

I am reseting my root VC in my app using:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())

let vc = storyboard.instantiateViewControllerWithIdentifier("testVc")

let navigationController = self.view.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([vc], animated: true)

So since I dont have a segue I have a sotyboard id for that VC. The only problem now is that I dont know how to add a navigation bar in my storyboard to that VC.

The VC shows up as completly white/empty in my storyboard but once I run my app and it gets assigned as root it also get a navigation bar which is right, but I would want to add one using storyboard and not code.

If I simply drag a navigation bar in storyboard and start the app. It will result in the navigation bar being placed under the other navigation bar.

在此处输入图片说明

在此处输入图片说明

You do not add a navigation bar in the storyboard. We're going to use the navigation controller's navigation bar.

You add a navigation item in the storyboard. Now you can configure, in the storyboard, what should be in the navigation bar when you are in a navigation interface.

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