Lord Vermillion
Lord Vermillion

Reputation: 5424

prepareForSegue for NavigationController in ViewController from stack

I have a segue between two navigationControllers:

enter image description here

How can i "catch" the segue in prepareForSegue in one of the ViewControllers in the NavigationControllers ViewController-stack?

Upvotes: 0

Views: 121

Answers (1)

Rob Norback
Rob Norback

Reputation: 6599

Navigation Controllers don't act as traditional view controllers.

How I would implement what you're asking is below, but I would first ask you: Why do you have two navigation controllers linking to eachother?

This is a very nontraditional use of navigation controllers. Navigation controllers simply control your navigation stack. They don't present any information to the user. My guess is if we looked at what you're trying to accomplish, this setup wouldn't be your best option.

That said, if you absolutely must accomplish something in the way you said above, here's how you could do it:

  1. If you'd like to use 'prepareForSegue' I would add a ViewController in the middle of the two navigation controllers.
  2. Then I would turn the alpha down to 0.0 for the ViewController
  3. In 'viewDidLoad' I would add the logic for seguing to either 'NavigationController' so that when you segue from one navigation controller it would hit the ViewController and immediately segue to the next navigation controller. Turning the alpha down to 0.0 would mean you wouldn't see the viewController (in theory, depending on your navigation stack).
  4. Then I'd add my setup to 'prepareForSegue'in the ViewController

Upvotes: 2

Related Questions