High again in this this and I assure you the container views and continued abuse are actually a part
of the IAB outlet.
I know in the past we have actually worked with the views that they called them container views but
they were the ones that we're going to do in this lesson in the system we will be using something that
is specifically called container review and it's essentially built for embedding one view controller
inside another one.
So essentially one view controller becomes a child of another view controller.
Now you might be wondering very is this system useful is essentially very useful when you want to reuse
ability when you want to be able to have one view controller and that gets reused over and over in different
parts of your application.
Imagine you have something like a star rating that you have developed or if you have something like
a set of fields that the user has to enter a value in it or if you have a little application that draws
a child and that child has to be shown in different parts of your application you can do redo this every
time you could use the system with it in the past.
And that is using a reusable you eye view or you could build its own view controller and use it within
a container view which is what I'm going to be showing you in this lesson.
So let's go further into its scope and start a new application called container view up.
That's a view view app.
I was my container view uploads up.
I'm going to head into my storyboard and here in the storyboard I'm going to go ahead and say I need
something called container review where the container review does.
And it says it in here is that defines a region that includes a child the view controller.
So I'm going to say this is my container review but it builds is this is built the way I view with another
view controller.
That view controller re sizes itself automatically.
So it fits within this view I view it has a Segway that connects these two together.
So in my newly created you a view which is that the boundaries for that I'm essentially going to go
ahead and place it in here and something to keep in mind is that this is just a you I view everything
that you have had for you I've used in the past now applies to this one.
So for instance I could go ahead and set some constraints for it.
I could say this is the top constraint This is the leading constraint.
This is the trailing constraint.
Say it's a VIT is equal to this.
At the height constraint for it which I'm going to change you manually lift even animates that to see
that it exactly works the same way but the content of this UI view comes from here.
So my view controller I'm going to go ahead and say it has a different background color.
This UI view controller can have its own class most likely should have its own class.
So I'm going to add a new one see cocoa touch class.
This is a subclass of UI view controller and I'm going to call this one green view controller so I have
the green view controller in here and in my story what I'm going to connect them to each other properly
so the class for this view controller becomes green view controller and then maybe a make an object
in here so an ad something called a label in here.
Let's place it somewhere in the middle and I'm going to make it larger.
Something like that.
Place it right there.
And then we have access to this label victim.
This you I view as well.
And that's something that I'm actually going to ask you guys to do in an exercise.
But for now I want to show you how they we represent each other.
Now we have these two.
Let's go ahead and run the application up until this point.
We should be able to see whatever it is inside this green you eye view controller or a screen you eye
view victim the way view which is embedded in our main view controller.
The one that's currently essentially white.
So let's run that.
And as you can see that's working the way we were expecting it.
There is a little problem with the constraints and that's because I didn't set any constraints for my
label.
So if I wanted I could essentially go ahead and say add all the missing constraints or now that's going
to be taken care of as well.
The next thing I want to show you is this.
I want to show you that this thing essentially is just a you eye view.
So I'm going to go in here and say in my view controllers let's do these things.
Let's go ahead and say I don't want to view the throat actually.
Let's go ahead and say this is let's call this one my container review container view.
So this is the you I view part of it.
I'm also going to get to its height constraint.
I'm going to say this is the height constraint constraint.
So now that you have these tools we could essentially do anything on them that you have been doing on
any other kind of object.
So for instance I'm going to say everything that touches and this is just the simpler way of you know
instead of adding a new button and a new function something I say when I touch make the height constraint
have a different value let's say it becomes five hundred and then animates that.
So you I view dot animates this is obviously not a very good you know practice with when we use container
views but I want to make sure you understand that this is just a UI view and it works exactly the way
everything has been working so far.
And of course here we have to say self DOD view dot.
You have to say layout if needed.
So you have to lay it out once again because we have changed the value and we do that in the animation.
So no they have that we should be able to run this and their view is kind of change its height I think
is going to become larger and the UI view controller is going to do the same thing as well.
So when I touch a boast become larger.
So the green view controller which is the other viewpoint to us being embedded in here is going to essentially
do the same thing as this UI viewer does.
And that's essentially all there is to a container view.
So this was a quick introduction to it in the next lesson.
I'm going to ask you guys as an exercise to do something more more complex and I'll see you there.