idelara
idelara

Reputation: 1816

What are Navigation Controllers for?

The title says it all. I am programming an app using Swift and Xcode 6 and I do not understand when I would have to add another one of those in my storyboard besides the one I start with.

When do I need another Navigation Controller? So far, I've done ok with transitioning between ViewControllers with segues. Therefore I was wondering in which cases would one need to use them.

Thank you for explaining!

Upvotes: 0

Views: 93

Answers (1)

Caleb
Caleb

Reputation: 124997

A navigation controller manages a stack of other ("content") view controllers. You only need one per stack, but it may happen that you have several different navigation stacks coexisting in the same app. For example, if you use a tab bar controller to create an app with several tabs, each tab may have its own navigation controller managing separate navigation stacks.

One app where you can see multiple nav controllers used with a tab controller (and which you already have on your iPhone) is Apple's Music app. The Playlists, Artists, and Songs tabs each have their own navigation controller. When you switch between those tabs, what you're really doing is telling the tab bar controller to make a given tab's view controller visible. In the case of any of those three tabs, the tab's view controller is a navigation controller, and when the selected tab's nav controller becomes visible it in turn makes the view controller at the top of it's stack visible. As you tap the different tabs, you can see that each one "remembers" which view is visible because the corresponding nav controller keeps track of its own stack of view controllers.

Upvotes: 2

Related Questions