Keeping navigation controller between storyboards (swift)

626 views Asked by At

I am creating an app with multiple storyboards. Right now, I am able to transition from the first storyboard to the second but when I transition to the second storyboard, I lose my navigation controller. However, I still need to navigate back to the first storyboard and would like to use the same controller. Does anyone know how to keep my navigation controller between storyboards?

Here's how I'm transitioning to my second storyboard. The pushViewController is my attempt to add to the navigation stack, but it doesn't work.

 let destination = UIStoryboard(name: "Preferences", bundle: nil)
 let initialViewController = destination.instantiateInitialViewController() as! UIViewController
 self.navigationController?.pushViewController(initialViewController, animated: true)
 self.presentViewController(initialViewController, animated: true, completion: nil)
1

There are 1 answers

1
Zhengjie On BEST ANSWER

I think U just add redundant code. delete

self.presentViewController(initialViewController, animated: true, completion: nil)

this code will present View not in the navigation container starker. This code make

self.navigationController?.pushViewController

do not work.

So just use

 let destination = UIStoryboard(name: "Preferences", bundle: nil)
 let initialViewController = destination.instantiateInitialViewController() as! UIViewController
 self.navigationController?.pushViewController(initialViewController, animated: true)