Hyder on will come back this lesson and the next three lessons are essentially interconnected to each
other.
So I really suggest that you try to do all of these four together at the same time.
And these are actually very very important lessons these are important concepts and important techniques
and things that you have to really master them.
So what are these is all about The View controllers.
So far everything that we have made there were actually elements of a view control.
They were being shown to us inside one view controller.
You can think of few contours as the pages.
Imagine you go to a website and you have a page for a home and you have a page for product and you have
a page for services on a page for contactors view contours or somehow a similar thing that for each
of those pages you would need a view controller.
So if you control that contains everything for a certain view and also provide interactivity lets you
tap on a text field and enter a value or click on a button and run a function.
So on and so forth.
So in this very first lesson of view controllers we're going to do something very simple and that is
just adding one new View Controller to our app.
So this code works code in here.
I'm going to close this project I'm going to start another one and call it view controllers.
Once that is good and ready.
I'm going to go for my storyboard on
this thing that we have in here so far this is essentially our view controller.
This is a view controller that is connected to a class also called The View Controller.
Don't be confused by the names of them.
These names are just things that we have given them.
This doesn't have to be called a view controller.
It could be called our home View Controller or main view Quenta or anything of the sort.
But that Typee you I view controller which is the type that is the superclass in here that has to stay.
And this is the view controller of the visual side of it that is connected to that class.
So for now just so that we don't make things overly complicated I'm going to add one more of your control.
I'm going to find the way to navigate from one to another one.
So let's go ahead in here.
I'm going to say up there.
Give me a new view controller.
So as you can see now I have to view controllers side by side.
And in order to make sure that they somehow are different from each other I'm going to change the background
color of either of them.
If you open this little view on your on the left side of your Interface Builder by pressing that little
button at the very bottom of the screen you can see the construct of each of these View control.
This is essentially the hierarchy of that scene.
This is one you control the scene and this is another view controller scene.
And each of them have some objects they have a view controller they have a view they have a first responder
so on and so forth.
Now the thing that I want to do is I want to select their view and that is by just clicking in here
and I want to go there and change their background color.
So one of them becomes green and then the other one on one and make it become some sort of a yellowish
color.
So so far I've managed to have two controllers that they seem quite identical except that there are
some differences between them.
The most notable difference is this little guy that is a little arrow that goes into the green one but
doesn't go to the yellow one.
And if I select my yellow one and go up here and say This one is initially a view controller that little
arrow comes in here I could you know drag it over and drop it to the other one.
And now this one becomes the initial view controller.
Let's see what that means.
I'm going to push this to the yellow one and run my application
as you have undoubtedly guessed.
Now we will see the yellow of your controller because that's the initial one.
And if I push this back to the green line and I read on my application of course this time we're going
to see the green View Controller showing up.
So that essentially says Veach view controller is my initial starting point for this application.
Now that I've done that I'm going to go in here I'm going to add a button and when I get in here I'm
going to place it somewhere in there.
I'm gonna say it's God actually is God.
A yellow ish the same yellow ish background.
And it says let's.
That's not how you type it.
Let's go to yes.
So this button is now meant to take us to the other view controller and we accomplished that by doing
something something called a segue.
Now what drove a Segway by holding the control brother and driving over to my other view controller.
I mean here I'm going I should say the action segment is the show at some point down the track.
I will talk to you about the different controllers and different types of segues.
But for now we're going to go with the default one that is sure which means whenever you press the yellow
one we will end up here.
So let's see how that works.
Perfect.
It takes us to the yellow one on you play select that little saying hey I can actually go in here on
lookout you know some of the things that is in here for instance I can change that kind of to be present
modeling.
And in the presentation I can change that transition to a B.
I don't know something like a flip horizontal.
Let's see how that works.
So now and I top it flips it's horizontally and it lands us in the yellow site.
Now let's imagine you want to have another view controller.
So I'm going to repeat this entire process once again.
I'm going to have another view controller and when I get in here this is my turn to view controller
in an in a in an intermediate application you usually have something about you know 10 to 15 new controllers
depending on you know the complexity and depending on the nature of your application.
So yeah I'm going to go ahead and add another but then just make the background in your read saw the
bag on this ping.
Why not.
And then I'm going to say Give me a button here and this farden I'm going to say it is like that.
Go to Penkridge.
All right.
And they go to pain are just like it makes more sense.
It is actually pink itself.
And the way it works is I hold the control by then and there I get over here and I say actions saying
they should.
Now if you run up occasion I'm sure you can guess it that from the green one you can go to a yellow
one and from the yellow one we can go to the pink trunk.
Of course each of them is using a different kind of transition.
So what did we do.
Let me delete that last one and let me do it Darwan.
So what we have done so far is that we are the new controller we are by then and we are the segue between
them by holding the control by them and dragging over the next window or the next View Controller.
Now what we we also need to do is we need to be able to program on this view controller data view controller
we already had the files for it and we were able to program for it.
This one we're still on are able to do that.
Imagine I wanted to do this.
Imagine I wanted to have a button that in here takes me back.
I'm going to say go back and I go back I'm going to say by gone is Noreen I cannot use a Segway to go
back again but I have to do is I have to programmatically dismiss my view controller and that's something
we are going to see in our next lesson.
We're going to see how we can program things in here because if you think about it this burden belongs
to the green view controller which by default was connected to view controller age and view controller
m.
So how are we going to program something for the yellow one.
How can another set of files appear here that are going to help us connect this view point order the
yellow one to another group of files that we're going to discuss and we're going to find out in our
next lesson.
Keep it up to here.
Like I said it would really help if you do these lessons back to back because you contours are such
large topics and I'm trying to jam as much as I can into these four lessons so you get a sense of a
functioning application in a very short span of time.
So with that in mind let's move on to the next lesson.