Ios - Navigation between multiple navigation controllers

I am trying to understand the navigation behavior between ViewControllers with (and without) using the NavigationController, and I don’t understand some things when reading articles and documents, so I decided to ask them.

Main question: What happened if we have several navigation controllers in the Storyboard and want to move from one to another? (And this can only be achieved using segues, as between regular VCs, am I right?)

As I understand it, NavigationController is a stack of ViewControllers, inside which we can pop and promote these VCs. So now we are changing our “location” from the VC of the first navigation controller to the VC from the second, what happens next? The first stack has disappeared and now we work only in the second? If so, does this mean that the VC stack of the first NavigationController has been removed from memory or not?

Maybe I completely misunderstand something or maybe not :). I will be glad to see your answers and hope to ask you more detailed questions about the navigation mechanism.

UPDATE

The fact is that: let them say that we have one (initial) VC with two buttons that represent two separate parts of the application. Then we press the first button and go to the RootVC of one NC, than we return to our initial VC, press the second button and go to another NC. What happened to the stack of the first NC when we get back to the original VC, and what is the best way to go “outside” the NC to the original VC?

UPDATE

I am trying to understand what is happening with the memory and which VCs are on the scene at the moment and so on. Maybe this is absolutely unimportant, if we have additional VCs on stage, maybe we need them to switch between NC (or only VC) faster. So I just want to understand how it works.

+6
source share
2 answers

Imagine that you have a standard application chain where you click / view the views in the initial navigation controller. Then imagine that you have another view that is not part of this chain, for example a user profile that you present as a modal view:

enter image description here

Now the top navigation controller is the initial one, so you start from this moment, and in order to use the second, you will need to access it through the UIStoryboard, like this (red arrow):

// Get storyboard let storyboard = UIStoryboard(name: name, bundle: NSBundle.mainBundle()) // Get profile NC let profileNC = storyboard.instantiateViewControllerWithIdentifier("LoginNC") as! UINavigationController 

But if you really want to present a profile from one part of the application, so it is not modal, you can do it as well (green arrow). The only difference is that now you do not need a second navigation controller, so you do not connect the push sega to the red NC, but directly to the login controller. If you are actually trying to connect the NC-NC, and then run it, you will get an exception at runtime, indicating that you did it wrong.

Memory

All VCs remain in memory, no matter how you represent them. This is also true for background views when you present something like modal. If you have memory problems due to long chains, you can implement the clear / cache logic in your controllers:

 func viewWillAppear(animated: Bool) { // Call super first super.viewWillAppear(animated) // Prepare UI } func viewWillDisappear(animated: Bool) { // Call super first super.viewWillAppear(animated) // do some memory cleanup, since view will not be visible atm } 

Hope this helps!

+4
source

What makes sense is to introduce a new UINavigationController with its child view controller from the existing one in the form of a modal dialog (this can be done using the modal segment). Each navigation controller has its own stack, and while you are busy in the dialog box, the "main" stack remains intact. When you release the dialogue, you will return to the "master".

I'm not sure that it is technically possible to push a navigation controller onto an existing one. It makes no sense.

0
source

All Articles