So welcoming and following from our previous lesson in this lesson we're going to talk about segues
in more details.
We're going to learn how to make segues between different view of controllers and also how to call them
programmatically.
We don't learn something that's called an unwind the segue.
So let's get started with that and then we're going to exclude.
I'm going to close this whole project and start a new one.
This one is called Single vilification secure Vai's up and in my segues are what I'm going to do is
I'm going to build two of your controllers.
I'm actually going to build three of them and I know we've done this before but I'm actually going to
go to everything once again so we kind of remember the whole process.
So what is going here you don't have to do it this way if you're a female constable already or you can
do it the way that we had in the previous lesson.
But if you want to follow me along on you know get a sense of how things are happening.
I'm going to go in here and say give me all these three files and delete all of them.
I'm going to move all of them to trash and then the next thing I'm going to do is I'm going to rebuild
all of them.
So first of all I'm going to make a new cocoa touch glass and it's going to be a view contour I'm going
to call it the main view controller.
And that's been there and then a lot.
And needed an added to my project because I was in the wrong place.
I'm just going to drag them in here.
Everything is going to work and I'm going to either another one or another one come on and I'm going
to call this one second the View Controller.
Again it's a subclass of view control I think is an objective c we know all of these things and I'm
not making an X I'll be fine for it.
And we show you that in the Terdiman.
So file new file or command and and then when we get in here coke with each class and is not it does
not have any type you find that this is going to be my turn to view control the
I know this a beautiful long way around but I find it that is deconstructing iPhone apps always helps
the students better understand what's going on.
So he's learned language and I'm going to go to all the dot h files and all of that H fun as I'm going
to remove everything I know I'm not going to need.
So he's basically importing a kit and having an interface.
So a game might at age for the other file which I don't even know what's its name.
Are you like kid on the interface.
Undeterred we have control of the same thing.
Not the pound sign.
Remove that and live with the DOT M-4s going glowering move almost absolutely everything.
So I don't need any of these guys not even the view that lower the view that lot is there for us so
we can use it.
Boy doesn't have to be there.
So I'm going to remove everything here as well in all the dot m fonts.
So essentially it becomes an interface so I can view a controller and implementation's I can be a controller.
Soon enough we'll will learn more about the classes and how do we do these things and what do they mean.
But for now I can imagine that the interface the Declaration and the implementation is the definition
of that class as coach will tell you controller do the same exercise and well remove everyone so clean
on you know everything is the way we want it.
Now remember we used to have a file called the main storyboard and I removed that one so I'm going to
have to add in US storyboarded as well.
So I'm going to have command and I'm going to go in here and say a storyboard.
That's what they want to add in here.
I'm going to say this find this card or you could quote it again main or you could call it say my visualizes
or just my or whatever you want to call it.
I'm going to call it actually Maine is a very good name for it.
That's why it's called Maine.
That is storable.
But since you're trying to rebuild everything.
I'm actually going to call this one.
Art Inish or home home are the story.
So now we have a file called home that a storyboard and there is nothing in it.
Now if you remember I could actually go ahead and add the view controllers.
I could go against a library say one of your controller.
I'm going to put it here.
That's going to be for my main view controller another view controller.
This one I'm going up with it for my second view controller and another one that's going to be my turn
to view controller.
So essentially rebuilding the whole thing and rebuilding this story was building the real control is
almost entirely everything.
This first new controller I'm going to go up here to the identity inspector and I'm going to call this
one to be my home or so it is called Main view controller and I'm going to select the second one.
And that's going to be the second view controller on the third one obviously is going to be the third
view from.
And since I'm going to do some navigation between them I'm going to have to change some of the colors
so we can know that you know we have navigated summer so I'm going to make the bag on this one ping
the back of the last line.
Let's say green.
Perfect.
Now the next thing I need is this one of these view controllers need needs to be my initial view controller
so I'm going to select this one and say is initially a view control and that little arrow shows up in
here.
Now here's a very interesting thing that happened here.
If if you have been really perceptive you have to be asking yourself this question since I can make
multiple store reports.
However the app note which is storyboards should find the app launcher from the storyboard will hold
onto the initial view controller.
And that's no magic that summer up here in our app settings.
So you go up here and you select your app and you will end up in the settings page of it on my screen
again.
Your select you up and you see the settings.
And in here we'll talk about some of these as we go through the lessons.
But one of the things that we need to know right away is this one in the deployment in for in general
settings.
There is something called the main interface his thing which is storyboard is going to be the main interface
for this application.
And since I don't have main anymore when open this I'm going to say home storyboard.
The one that we made ourselves.
This one.
So now that's how you choose which is storyboard to be the main a storyboard for your application.
And of course you can navigate from one storyboard to another one and that's something that we see in
a few sections and we talked about that you are an obligation toward us.
So not my story but I have to give you controllers on one of them the white one is going to launch by
default.
But what they do want is I want go from one of them to the other one and then from that one to a third
one and then going back to bowse one a step back from green to pink and pink to white.
And I also want to see a way forward going all the way from Green back to the white one.
So let's see what they're going to do.
I'm glad somebody else is going to be very simple stuff so.
But then on this Baden's let's say it's got a pinkish background and it's as you go through second through
cycles and that's the pink you and I thought they gave it bag on the car apparently not OK.
So I'm going to copy this now.
My Magic Mouse my mouse always gives me some difficulties happening multiple times.
I should get a new one I guess.
So here I doing the new one and this one says go to Tirtha And of course Third is the green one.
I'm going to change the background of that to be green and then I'm going to have another by then and
here and this one says
go to WHY IS MY MOUSE doing this go to Homer on the home is obviously the white one.
Let's call this one go back home.
OK.
And this is the one that is Bangon gets to be the right color once again for some reason my mouse is
playing a trick on me.
But you know it's going to come and that's going to be the white color.
Perfect.
I'm going to copy both of these.
All of these are two buttons.
I'm going to take them to my last view controller.
The Tirith The View Controller.
I don't know yet I'm going to have two different buttons one of them is going to be saying go back to
pink.
So this one the top one is going to be let me write it.
There you go back to second which is the Pinchon ping pong ping.
Right.
And of course he's got a pinkish Bangon color.
And I thought I gave it pink.
So the top one is going to be pink that's as Colback the second.
And this one says go back all the way to the home.
You go back all the way home.
Perfect.
So here's what I'm going to do.
Now I know the last time we did this you were actually driving with control from Ibadan directly to
this view.
Controllers you stand with that do things a little bit differently.
And this is how you're going to do that.
First of all I'm going to make my segues between View controllers.
So I'm going to select from one view control the outlets to the other one on one to say this is one
Segway.
And then I'm going to make another one from here to there.
That's another Segway sort of segues that we make for we are going you know deeper into the view controllers.
We're going to make it from one view controller to another one and then from this I can be open for
it.
The last one.
And then we need to know what are the names of those view controllers.
This one I'm sorry to say is this one I'm going to call it to pink silk.
And I usually like to end it with an IED because that's an identifier for the Segway.
I want to call it to ping Segway ID and this one I'm going to call to Green say Devey.
I can imagine a real life situation you would call this one.
I not to contact Segway ID or to a story Segway idea depending on what that you can or is going to show
you.
Then the next thing is we have to make the actions for our buttons.
So I'm going to go to my assistant window.
I'm going to first go to the main view controller on here I'm going to see main view controller that
age on the function I want to make is go to secant.
So here we go to two second action.
That's the first function.
Then I'm going to go to a pink one and a pink one.
Of course I'm going to look at this I can view control of that age and here and make it a function or
an action called gold to turn action.
Perfect.
So we have these two taking care of.
Now I also have another broadening here in the in the second view going or what is pink.
So I'm going to make another one in here and this one I'm going to call it an action saying go back
home action.
So that's the action that's going to take us back home.
And then in the third one which is the green view controller I'm going along the head you control that
H and in here I'm going to say this one is an action called Go back to the second action.
So everything is named an order and they have functions properly.
Remember this one.
I still don't have anything for it.
The one that takes us back all the way to the other side.
So this first program these guys.
I'm going to my main view controller that am on here when we have to go to secant.
I'm going to call a very simple function and that is is being self per form secure way with identifier.
So you're saying perform a Segway.
So what Segway would I want to perform this one.
The one whose identifier is to pink Segway ID.
So I'm going to go to maybe your point for that and I'm going to say the idea for the identification
for it is helping Segway idea.
I don't have a sense that I don't want to send any particular information.
So that's going to take us to the other one.
Now let's repeat the same thing for when we go from the Pinchon to the green one.
Remember the sick race car to dream the Segway I.D. and we already have the function in there.
So in the second controller when it says go to tared action I'm going to say self perform for the sake
of a identifier and that's the identifier and my sender is Ned right now in my psyche and The View Controller
Dot and I also have that go back which you already saw self dismiss view controller.
Yes I animated it and don't do anything at completion.
So that's how we can go back and I'm going to have the exact same piece of code for the you control
that and when we want to go back.
So that's about once again really quickly from main view.
Control yourself perform sync with the identifier.
That takes us to a second that either fire is set in or sake of a in here and then an other cigarette.
We have another identifier and every time we want to go back we simply call this self dismissal controller.
Keep in mind dismissing of your control it means in the stack of the view controllers that you have
gone deeper and deeper as they were nested just go back to one stage.
It doesn't mean go back all the way to that one or to any particular view contour.
It simply means go back one step behind.
So let's run this operation
once it launches
I should be able to go from here from the pink one to the green one.
So if I'm the right one to think on from the pink one the green one.
And then I can go back to the pink I can go by the way.
Exactly the baby they're hoping everything is going to work.
Now the only by then that doesn't work is this one going back all the way home.
Let me show you how we do that.
This is the last bit of this lesson is actually quite easy.
I'm going to go to my art white view control what is called the main viewpoint order.
I'm going to add a new action manually and this one I'm going to call it low back to home.
Right.
And what go back to home does it doesn't it doesn't matter what does that is what kind of argument it
has.
And it has a UI.
The story of your Segway storyboard Segway.
You can call it whatever you want to call it.
Now I'm going to take this matter.
I'm going to go to my dad and I dad as well.
And again my method doesn't really do anything you could do things in it.
For instance when you're on winding and you're going back from multiple nested view controllers you
could actually do things you could send data or whatnot.
But for now the only thing that really matters for it is that it is there it exists in here now and
this part is going to become a little bit confusing.
So far everything we have done we have relied on a relationship between a View Controller of visual
outlet in our storyboard as well as a view controller class.
So main view controller that H-1 and very connected to this guy.
The second view controller that H-1 and they were connected to this guy and the same thing for the last
one.
This time however we are going to call a method in here in our terror the view controller but we we're
going to call it from main view controller.
So there has to be a connector.
Now the moment you have something in here in your any of your view controllers that has a UI as storyboards
segue into it as an argument it means you can call them gear in the exit.
So in the exits I could actually go ahead and say and go back home.
This is the function we have received as a presenting segue from another view controller looking here.
If I actually go ahead and I Carmens this out I.
Common doors out.
And then the moment I go back to my storyboard Now these control these exit outlets they have nothing
on them so no matter how much you try to control and drive over them they won't show anything to you
simply because they don't have anything but the moment you have a back in any of your of your controllers.
They even appear in that outlet.
So in here in the story we're now I can go ahead and say this one.
I want to be on this guy as an action for it.
So now they're connected to each other.
Let's see how they work.
If all goes well we should be able to go from our Obviously code dive into the green one and then thrist
this one to go back all the way to the white one to get rid of the entire stack and go back and does
what we call an on line the same way.
So that's about that.
We now saw how we could drill down inside multiple layers of view controllers using segues that they
do have identifiers and that we can actually make a lot of different kinds of applications.
The one thing we haven't done and that's the thing I'm going to leave for the next Listen daddy is sending
a message to segues to the next view controller semi-human I press on this one I go to the page I want
to see something here.
So with that in mind let's move on to our next lesson.