Right, we're pretty close to completing our app, believe it or not, we have a screen with a button
in it, but now we need that button to actually do something.
And the way we do that is by having an action outlet, which is basically fancy speak for saying something
that listens to the click of the button.
Now, remember, I said we don't put a certain code in the view controller button clicks are definitely
code.
We do put in The View controller because that's the view controllers job, right?
Control of you.
Listen to events and button clicks, taps and things like that.
So I've opened The View controller, but you might wonder how do I connect that particular button to
The View controller?
Well, it's pretty simple.
So close the view controller and up on the top, right.
You have this little plus icon.
Add Ed on.
Right.
And if you tap that, it should open a new window for you.
Then what you can do is grab your view controller.
Just tap it, just tap the file view controller and then let's go find our screen for Main Storyboard.
Hello.
There it is.
Right.
We got our main storyboard.
I'm going to zoom out.
There we go.
OK, so with a bit of jiggery pocari, you can actually get these two things side by side.
Now if you don't have enough room again at the bottom of the screen here underneath the main storyboard,
you can hide the document outline.
It's very, very tiny icon.
Thanks Xcode.
And if you click it, you can actually show that without showing all that extra information.
Right.
So all we have to do is click the button, hold down control, not command, but control.
This is the left control I'm using.
Click on the button.
And drag it over and you'll notice it says insert action outlet or outlet collection, I'll tell you
what those mean in a second, but you have to drop them, not outside the class.
It won't let you do that, but inside the class and not inside any of the functions.
So it's going to be its own function.
And when you release the mouse button, you get a tiny font apple.
You have action outlet, outlet, collection.
Well, this is an action.
A tap is an action.
So we want that.
And then we have the object view controller.
Don't worry about that for now.
Although, wait, wait, wait, wait.
What have I done here?
No, I think we're good action outlet view controller name.
We can give this function and name.
So what are we going to say?
Button tapped.
And then type is going to be button up button.
I'll explain what these are in a sec.
Now, here's the weird one, look at all these options we have for the event that this responds to.
So you might think of a button is just a tap, but it ain't just a tap.
There's an event for when you first touch it as an event, if you move your finger is an event.
If you release your finger, there's an event that covers all of those.
There's loads and loads of events.
Apple has a very strange way of naming things.
It's called Touch Up Inside for the classic tap.
It is what it is.
And just don't worry about that, then hit connect, right, so now we have our first little bit of
code.
This is an I.B. action, an interface builder action on the left side.
That is an interface builder.
On the right side, it's an action from the interface builder.
So that makes sense.
There's the name of it, button tapped and the sender gives you a connection to the actual button that's
being pressed.
So if you want to change some text on the button, for example, you could easily do that within code
without going on a long journey to make that happen.
You'll also notice there's this little gray icon.
And when I hover over it, this is on line 17.
You can see the button light up.
Right, that indicates that connection also, if you click the button itself in this state and at the
very top right, there is a little circle called connections.
Inspecteur, if you click that, it tells you touch up inside is connected to view controller button
tapped.
You can remove that connection if you wish.
So that's how you edit your connections.
So if we play that.
Where's our simulator?
There it is now we should see the button on screen and we can tap it and nothing happens.
But in the background that is being called.
OK, so that's how we connect user interface elements to the code, and this is the pattern you're going
to see all over the place with iOS.