Florian Pfisterer
Florian Pfisterer

Reputation: 1265

How to jump to any ViewController in another UINavigationController

I have a project created with a storyboard. There I have many ViewControllers, connected with segues. Now I want to get from ViewController (VC in the following) A , which is embedded in a navigationController (as RootVC) and presented with a modal segue by another VC B (which is also presented by another VC C modally) to any other VC D in the storyboard (In this case the first one in the main Navigation Controller E). I experienced that the NavigationController hierarchy is "destroyed" by a modal segue, and because I need the function to use push segue in VC A, I need to use a second NavigationController... I've already tried to save an instance of the destination VC D globally and then jump there with

    self.navigationController.popToViewController(myDestinationVC_D, animated: true)

But then I get an error because of a nil-optional that was unpacked.

I hope you can help me. I think the given information should be enough, but if you need more, just comment. (I hope my English is not too bad ;)) Thank you !

Upvotes: 3

Views: 4523

Answers (2)

ergunkocak
ergunkocak

Reputation: 3380

Swift version :

navigationController!.pushViewController(storyboard!.instantiateViewControllerWithIdentifier("View Controller Identifier") as UIViewController, animated: true)

Upvotes: 1

Schemetrical
Schemetrical

Reputation: 5536

I'm going to write in objective-c but I'm sure you can convert to swift.

some *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"some identifier you add to a vc in the storyboard"];

and just push to view.

Upvotes: 1

Related Questions