Hi and welcome back.
In this listen I'm going to show you how to combine navigation controllers as well as the tab bar controllers.
It's not such a difficult process.
What they often find is that guys that are new to the day struggle.
So I tell I'd quickly show it to you so you know what you have to do.
So that's going to explode and I'm going to load up a score and say I have a single view application
I'm going to call a tab bar and navigation controller.
Now my tab bottom navigation controller I'm going to head into the storyboard industry what I'm actually
going to delete everything.
So I have none of these objects.
I want to build everything from scratch.
You could actually delete your view controller as well if you wanted to essentially build everything
right off the beginning.
So the first thing I need is a tab bar controller.
I'm going to go in here and say Give me a tab bar controller and that's my starting point for this application
is a top or controller that has two items each item essentially represents a one view controller.
And now I'm going to change the color of both of those view controllers.
One of them I'm going to make it.
Maybe this kind of shade of blue and then this one I'm going to make it a type of green.
So I have two view controllers and as you know the relationship between this view controller and the
blue one or the green one is off the type view controllers array.
Let me delete one of them and rebuild it so we have a refresh on that.
While the control button right over here.
And the type of relationship we want is the view controllers.
So that's an array that takes on so many view controllers.
Now that's the default version.
We have been doing so far.
But if I wanted to embed these view controllers in a navigation controller I could simply select them
and say this one for instance has a an embezzlement with in a navigation controller.
And then when the new navigation country gets created essentially that navigation controller becomes
one of the view controllers of my top or controller.
So now the Green view controller.
We just appear.
That's item two.
Let's go ahead and change that so we know what it says that one says Green.
And then the other one.
And when I go ahead and yeah I'll say it says blue.
So now the green one obviously it just appears the blue one appears with a navigation controller and
any from the blue one.
We want to go somewhere and I would have another view controller.
Let's say this new view controller is going to be the view controller that is pink.
And if I have a button I can simply say some of the things I'm doing might seem repetitive.
You guys you guys know how to do it.
They just want to have a quick you know refresher of everything to make sure that we all know how to
use all of these things.
So from the pink fun I can do a controlled drag going here and say Sure.
Now before I go ahead and run this application in the simulator I'm going to go ahead and select my
tab bar controller and say this stop or a controller is the initial view controller.
So someone would launch this storyboard essentially and then I'm going to go ahead and run the application
when the application loads up I should be able to see one of my items as a navigation controller.
The other one as a normal view controller.
So green is the regular view controller and the Blue has a navigation bar up there.
And if I tap on this pink I'm going to go to the pink view controller where there is a backed by that.
Now that's in essence all there is to it.
You can obviously add classes in here for your game view controller for your navigation controller if
you need it to do something for your actual other two view controllers.
Now the last thing I want to show you in here is how to embed your tab for controller with in a navigation
controller.
Now if you imagine we can have something like this we can go in here and say I have a navigation controller
that navigation controller by default makes a table view which we're going to delete on where I get
in here and say for my navigation controller the TAB board controller is the route.
So I'm going to hold the control right over here and say tab ball control is the route to view controller.
And of course I'm going to go ahead and select my navigation controller to be the initial view controller.
Now the problem with this system is this the moment the uploads.
This is storyboard launches the navigation controller which launches the tab or controller which launches
one of these two view controllers.
And we will have one navigation controller controlling a tab bar controller which controllers and other
navigation controller.
And essentially when we end up here we want to know which of the two navigation controllers are being
shown to us.
And I can tell you the top navigation controller will be there to make things a little bit more interesting
and show you the area that's going to happen with this system.
I'm actually going to make one view controller between these two.
So this go ahead in here and say I don't have that but they do have is a view controller such as this
one and this view controller is in between these two.
Let's go ahead and make it have a different background color such as this dark orange and I will have
a by then
that's going to take us to the top.
Barak entourage essentially sort of has a different background as a may be white and it says go to tap
now for the navigation controller.
My orange is going to be the root fuel controller or hold the control that I go over here.
That's the route of your controller and my navigation controller is the initiated view controller.
Then when I type on this at some point in our application if you want to go to the tap or we're gonna
go to a section of our application which has a tab what so for doing that control drive over here and
then I say sure.
And then he's gonna have the navigation controller on top of the tab or controller and then it has the
rest of the things that we have designed let's go and see how this one plays.
If we have it in the simulator reach after two navigation controls over our pier I'm actually going
to show you everything in the background so we can see the little bit larger.
So we know all the design in our mind.
So here is my simulator.
And right off the cuff the moment the app began for events with navigation controller and we ended up
in the dark orange view from there.
I'm going to had the go to tap and then we end up in the green because that's the default view controller
of our top or controller.
And then if I go the blue one we obviously pass through the navigation control and become here to where
we see the pink.
By then if I type on the pink but then I end up in the pink view controller.
And here is where the system breaks.
If I press on the back by then I expectation is to go back to the blue.
But that's not what's going to happen when I press the back.
We actually end up all living here simply because when a person the go to tab and this navigation bar
appeared up there that is on top of everything in there.
And even when I go to the next level and I press the pink again and we have another navigation bar showing
up that one is taking precedence because of that that because it has priority that's one is the one
that's being activated when I press the rack within.
So the solution to that is something quite logical.
The logic of it is well we already have one navigation controller.
Why would they want another one.
And because of that I'm going to go ahead in here and say Let's delete this one instead save from the
TAB Balkans order the blue one becomes another one of the view controllers.
So essentially we drop the middle man middle object in there.
Let's go ahead and running the game and this time a lot we should be able to navigate properly.
Go to tab which takes us to hear that hard ball controller.
Go to the other item which takes us here and then from there on go to pink which takes us to the pink
and then from the pink back to the blue.
And then from the blue back to the top bar and then going back to the taps and we end up in here.
The only real problem in here is now the Green view controller and whatever that you know succeeds that
David also have the navigation controller because we came from some sort of navigation controller.
And if your goal was not to show the navigation bar in this group of view controllers then you can just
say self that navigation item that hidden is true and you can hide the navigation bar in here.
Otherwise with this system we can go through one navigation to control another view controller a group
of TAB or controller items view controllers or what not.
And in all of them we have a way to navigate back and forth between our different group of items essentially
which is quite useful and a lot of application they benefit from such a system.
So let's keep it up to here and let's move on to our next lesson.