1 00:00:01,880 --> 00:00:08,930 So will come back again in this list and we're going to talk about Bartons views pardons for a variety 2 00:00:08,930 --> 00:00:16,130 of things for calling functions for revealing values for submitting forms for logging in a user. 3 00:00:16,220 --> 00:00:21,130 So Boland's all of those are fundamental pieces of any Iowas application. 4 00:00:21,350 --> 00:00:25,370 So let's go ahead and get started making some burns. 5 00:00:25,470 --> 00:00:28,270 Of those books Lexcorp I'm going to start a new project. 6 00:00:28,370 --> 00:00:34,520 This is going to be an Iowa single new application and I'm going to call it Baden's. 7 00:00:35,100 --> 00:00:45,110 And then my Baden's up once it loads up when I go to my main storyboard I'm going to show you several 8 00:00:45,110 --> 00:00:49,450 different ways of making by then obviously if you start from the simplest one. 9 00:00:49,730 --> 00:00:55,500 So in the simplest one I'm going to go to a library and here I'm going to search for buttons. 10 00:00:55,640 --> 00:00:57,670 I'm going to add a button. 11 00:00:57,710 --> 00:01:02,730 So this is a button that I have and I'm going to place it in here. 12 00:01:03,260 --> 00:01:05,350 Let's go to the attributes. 13 00:01:05,390 --> 00:01:06,460 Let me bring that up. 14 00:01:06,470 --> 00:01:13,340 Call it our top on this and I'm going to go with a different background. 15 00:01:13,580 --> 00:01:16,480 So it is more clearly visible. 16 00:01:16,700 --> 00:01:18,650 Maybe not that one. 17 00:01:18,770 --> 00:01:22,040 Maybe that was a porcelain actually. 18 00:01:22,990 --> 00:01:25,770 So dark was good. 19 00:01:26,080 --> 00:01:30,680 And then when I'm going to do is I'm going to add a label in here. 20 00:01:30,760 --> 00:01:37,080 So here is that label I'm going to label that as above. 21 00:01:37,980 --> 00:01:46,980 Perfect my label is aligned to the sun a little bit larger and it has a background of pink. 22 00:01:47,220 --> 00:01:48,780 That's all I'm doing here. 23 00:01:48,780 --> 00:01:53,700 So the next thing I'm going to do is I'm going to actually go ahead and connect these outlets to my 24 00:01:53,970 --> 00:01:59,850 programming interface so to do that I'm going to go to the assistant editor and the assistant and I'm 25 00:01:59,850 --> 00:02:06,360 going to make sure that I have my user interface loader in one side and my daughter age on the other 26 00:02:06,360 --> 00:02:07,330 side. 27 00:02:07,510 --> 00:02:13,950 At that age I'm going to go ahead hold control and drag my label and hitting the out that I'm going 28 00:02:13,950 --> 00:02:14,690 to say. 29 00:02:14,730 --> 00:02:18,060 It's called resort labor. 30 00:02:18,570 --> 00:02:24,200 And now the connection type is an outlet to remember that connect. 31 00:02:24,410 --> 00:02:32,660 But when I'm driving my car then I'm driving this over here and the connection type I'm going to change 32 00:02:32,660 --> 00:02:35,240 it from outlet to be an action. 33 00:02:35,280 --> 00:02:42,240 So this time when this thing gets stopped on I want something to happen to change a connection to an 34 00:02:42,240 --> 00:02:43,260 action. 35 00:02:43,430 --> 00:02:48,900 I don't want to call it our top action. 36 00:02:49,130 --> 00:02:51,960 So let's see what we get. 37 00:02:52,080 --> 00:02:55,190 So fine go back to the other two I'm not. 38 00:02:55,290 --> 00:02:57,690 I go to my dad page in here. 39 00:02:57,690 --> 00:03:06,050 I have one property that is declaring declaring the outlets right. 40 00:03:06,120 --> 00:03:16,110 Take Larry out with or without declaring the outlet and then I have an action an action which is to 41 00:03:16,110 --> 00:03:23,610 be triggered every time we stop on that button and I have the same action in my dad am and he's asking 42 00:03:23,610 --> 00:03:27,050 me to fill the body of my function. 43 00:03:27,060 --> 00:03:33,580 Actions and functions can be used interchangeably in innocuous I mean in terms of terminology. 44 00:03:33,600 --> 00:03:41,220 So this is again a function so I can call the function and I have to not do something in the body of 45 00:03:41,220 --> 00:03:42,380 the function. 46 00:03:42,420 --> 00:03:45,800 Now let's go ahead and do that before I do anything. 47 00:03:45,820 --> 00:03:51,550 I want to clean my cord so it's not very overwhelming so I'm going to go to that age and want to get 48 00:03:51,550 --> 00:03:53,550 rid of everything that is up there. 49 00:03:53,550 --> 00:03:54,710 That's my interface. 50 00:03:54,960 --> 00:03:58,320 That's the outlet that made this is the action. 51 00:03:58,320 --> 00:04:03,950 So we know there's only these two lines and they're both made automatically using the assistant editor. 52 00:04:04,100 --> 00:04:11,830 And I can go to my daughter then I can remove everything up there I can at it's my view to a lot. 53 00:04:11,940 --> 00:04:14,900 You could actually delete the entire interface as well. 54 00:04:14,910 --> 00:04:18,250 This is a private interface for that. 55 00:04:18,280 --> 00:04:20,040 And we'll talk about that in the future. 56 00:04:20,050 --> 00:04:26,090 But you don't really need it for now so you can read that and just keep the implementation here. 57 00:04:26,100 --> 00:04:29,340 So what do we want to happen when we stop on that button. 58 00:04:29,340 --> 00:04:31,500 I want the label in here. 59 00:04:31,830 --> 00:04:34,200 This one is called the resort label. 60 00:04:34,200 --> 00:04:35,660 I want to show my name. 61 00:04:35,670 --> 00:04:43,890 So when I go in here and say well read the label dot text and now that we have a bit of a better understanding 62 00:04:43,890 --> 00:04:48,820 about programming we can see that text is expecting and this is Thring. 63 00:04:49,010 --> 00:04:54,850 So text becomes my name and what I mean. 64 00:04:54,870 --> 00:04:56,280 So that's about that. 65 00:04:56,280 --> 00:05:02,730 So we have that is off label and the text becomes a mirror every time we stop and let's try this socage 66 00:05:04,500 --> 00:05:07,670 once it launches on the simulator. 67 00:05:10,840 --> 00:05:14,900 However if it does show up sometime today. 68 00:05:14,920 --> 00:05:15,600 OK. 69 00:05:15,830 --> 00:05:20,320 So when I tap this label it becomes I mean perfect. 70 00:05:20,330 --> 00:05:25,720 So we might manage to make a a button that triggers something. 71 00:05:25,720 --> 00:05:29,680 And this is the very first time we are doing something interactive. 72 00:05:29,690 --> 00:05:32,950 Now let's quickly have a look at what we have done. 73 00:05:33,380 --> 00:05:40,190 So in our age we have a property that is connected to our label and we have an action that is connected 74 00:05:40,190 --> 00:05:41,470 to a button. 75 00:05:41,510 --> 00:05:47,800 What if I had another action let's write the shown on our on and try to connect that to our product. 76 00:05:47,890 --> 00:05:57,650 We want to go in here and say it's an IB action and it's going to be called my sac in action and that's 77 00:05:57,650 --> 00:05:58,160 about that. 78 00:05:58,190 --> 00:06:02,370 So I have another action very similar to this format up there. 79 00:06:02,390 --> 00:06:09,470 There was the return of an IB action interface based auction and they both receive any kind of send. 80 00:06:09,470 --> 00:06:15,670 So essentially what it is a body in order a segment the sequence or anyone can essentially trigger them. 81 00:06:15,680 --> 00:06:21,350 Now this little icon on the side it shows us that these two are connected to some one but this one the 82 00:06:21,350 --> 00:06:23,960 new one is not connected to anyone. 83 00:06:24,080 --> 00:06:26,610 So let's see how we could actually connect them. 84 00:06:26,690 --> 00:06:30,080 I'm going to go to my main storyboard and my main storyboard. 85 00:06:30,110 --> 00:06:37,100 I'm going to select the view controller on top of my view controllers interface when I select that and 86 00:06:37,100 --> 00:06:40,520 I'm going to go up here into the connections inspector. 87 00:06:40,760 --> 00:06:47,260 So up here in the connection the inspector tells me Reza label is connected to there. 88 00:06:47,330 --> 00:06:53,110 It also tells me that the action on touch up inside is connected to that. 89 00:06:53,110 --> 00:06:54,000 Pardon me. 90 00:06:54,080 --> 00:06:55,540 Zoom out a little bit. 91 00:06:55,550 --> 00:06:56,400 That one. 92 00:06:56,660 --> 00:06:58,030 So here's what I'm going to do. 93 00:06:58,040 --> 00:07:03,280 I'm going to say let's remove that connection and we'll press the red cross on the side. 94 00:07:03,290 --> 00:07:07,200 And I'm going to connect my second action right. 95 00:07:07,360 --> 00:07:08,610 One in here. 96 00:07:08,660 --> 00:07:09,580 I'm going let's go. 97 00:07:09,590 --> 00:07:15,600 A little window pops and says in what situation would you like to run this action. 98 00:07:15,620 --> 00:07:19,840 And I'm going to say I want to run it when I touch up inside the button. 99 00:07:19,850 --> 00:07:27,390 That means I let go of that touch inside the body of that button which is the default behavior. 100 00:07:28,040 --> 00:07:34,250 Now you might be wondering so where were these things when we were doing them using the assistant editor. 101 00:07:34,250 --> 00:07:36,400 So let's show it one more time. 102 00:07:36,590 --> 00:07:39,120 And yet I'm going to go to the assistant director again. 103 00:07:39,300 --> 00:07:40,790 Yes it's not on the right. 104 00:07:40,790 --> 00:07:44,090 I have the H on the left they have my storyboard. 105 00:07:44,420 --> 00:07:50,560 I'm going to drive more one anywhere here and here I'm going to say in a sort of an outlet make an action. 106 00:07:50,930 --> 00:07:54,790 And in here it says in what events do you want to call. 107 00:07:54,800 --> 00:07:59,280 That's what I say in touch up inside and that's the default behavior. 108 00:07:59,510 --> 00:08:03,780 That's how it got called the first time we made the action. 109 00:08:03,980 --> 00:08:07,450 So if you do it by dragging over that's how you do it. 110 00:08:07,460 --> 00:08:13,490 If you want to do it manually you can just write your own method or function in here and then go back 111 00:08:13,490 --> 00:08:20,000 to your restorable storyboards select your files on enter and then go to the connections later and connect 112 00:08:20,000 --> 00:08:21,190 the one that you want. 113 00:08:21,380 --> 00:08:26,940 So I'm going to connect my second action and say touch up inside. 114 00:08:27,230 --> 00:08:34,780 So now whenever this button is tapped on this function will it be caught my second action. 115 00:08:35,120 --> 00:08:40,990 But my second action doesn't have any body on the body of the that should be written in that thought 116 00:08:41,030 --> 00:08:41,730 Am. 117 00:08:41,820 --> 00:08:47,300 So just like the last time I'm going to have to bring this function once again in here and write the 118 00:08:47,300 --> 00:08:49,980 body off it may be in the body of it. 119 00:08:50,000 --> 00:08:56,610 I want the same thing happen I want it to say hello world. 120 00:08:56,660 --> 00:08:57,930 So let's run this now. 121 00:09:06,210 --> 00:09:08,940 And then we stop this one says hello world. 122 00:09:09,570 --> 00:09:16,800 Another thing that you want to keep in mind is everything here is essentially in the same format. 123 00:09:16,890 --> 00:09:21,930 So the property is this one is Can they connect that it's called the record label. 124 00:09:21,930 --> 00:09:25,960 If you want to connect it to a different property you just changed that name. 125 00:09:25,960 --> 00:09:29,390 Let's call this on my label. 126 00:09:29,640 --> 00:09:36,780 And now if I go to my storyboard I can go up here and it says the outlets that I have is there is a 127 00:09:36,780 --> 00:09:43,350 label on my label I'm going to disconnected from resurvey but I'm actually connected to the my label 128 00:09:44,220 --> 00:09:45,500 and that's about that. 129 00:09:45,500 --> 00:09:53,310 So now we made that connection between my label and this guy and that one didn't disappear for some 130 00:09:53,310 --> 00:09:53,730 reason. 131 00:09:53,730 --> 00:09:55,760 That made me select everything OK. 132 00:09:55,860 --> 00:09:59,060 So it's now updated and refreshed properly. 133 00:09:59,170 --> 00:10:06,330 So now obviously whatever we want to do we have to do it on an outlet called my label because red label 134 00:10:06,330 --> 00:10:09,070 doesn't exist in our interface anymore. 135 00:10:09,420 --> 00:10:11,070 So that's about that. 136 00:10:11,070 --> 00:10:17,390 Another thing that you might be wondering is why didn't think it would use an outlet for our label. 137 00:10:17,610 --> 00:10:20,420 But we didn't want to use one for our. 138 00:10:20,430 --> 00:10:24,420 But then how come our body doesn't need an outlet. 139 00:10:24,420 --> 00:10:27,130 The reason is our button itself. 140 00:10:27,150 --> 00:10:31,170 You're not really doing anything right if you're just calling an action on it. 141 00:10:31,290 --> 00:10:38,110 If you wanted to make your actions programmatically then we needed to introduce our buttons as well. 142 00:10:38,310 --> 00:10:40,050 Let's see how that works. 143 00:10:40,170 --> 00:10:41,320 So here's what I'm going to do. 144 00:10:41,580 --> 00:10:43,210 I'm well remove my labor. 145 00:10:43,350 --> 00:10:45,680 I'm going to say only better is labor. 146 00:10:46,020 --> 00:10:53,420 I'm working with most of my action or both of my functions so I only have one label in here. 147 00:10:53,430 --> 00:10:58,710 Let's go to the storyboard and the centrist thing thing because if you run the application if I run 148 00:10:58,710 --> 00:11:01,320 the application it would actually crash. 149 00:11:01,320 --> 00:11:07,290 And the reason for it is it's saying I'm looking for someone called my label but that doesn't exist 150 00:11:07,290 --> 00:11:07,830 anymore. 151 00:11:07,920 --> 00:11:10,270 Somehow you have deleted that. 152 00:11:10,500 --> 00:11:12,050 So I'm going to get rid of it. 153 00:11:12,240 --> 00:11:14,240 So no that's not there anymore. 154 00:11:14,460 --> 00:11:20,990 I'm also going to say there is no function here because we have actually deleted that function as well. 155 00:11:21,220 --> 00:11:23,280 And now here's what we're going to be doing. 156 00:11:23,520 --> 00:11:26,250 I'm going to say this goes to the assistant editor. 157 00:11:26,880 --> 00:11:34,910 And here there I might buy them in here and call it my button. 158 00:11:35,160 --> 00:11:40,310 Now remember this time I'm not making an action or making an outlet. 159 00:11:40,550 --> 00:11:46,770 So now I have my pardon and we have the arrest label which is not connected. 160 00:11:46,770 --> 00:11:49,790 So let's go ahead and connect that in here. 161 00:11:49,800 --> 00:11:52,760 I'm going to say it the label is disgusting. 162 00:11:52,890 --> 00:11:55,690 So they're both now properly connected. 163 00:11:55,700 --> 00:12:01,650 Now let's jump back into that again and I'm going to quickly refresh your memory that if we don't meet 164 00:12:01,710 --> 00:12:10,600 these guys we might buy them that thing exists and we do have read the label also. 165 00:12:10,750 --> 00:12:12,250 That thing is there. 166 00:12:12,450 --> 00:12:18,390 So this time around we have the pardon but it's not calling a function hobbit's outlet. 167 00:12:18,450 --> 00:12:25,140 So how could we call a function here and we're going here and this is how we do it programmatically. 168 00:12:25,140 --> 00:12:29,290 I'm going to say might buy them at the target. 169 00:12:29,610 --> 00:12:33,450 And now let's see what is this odd target which is a bit of a mouthful. 170 00:12:33,450 --> 00:12:36,770 You know function has got several different parameters in it. 171 00:12:37,000 --> 00:12:39,890 I a all of them so it's a little bit easier. 172 00:12:40,070 --> 00:12:42,910 Bill makes sense in end just as I can to you. 173 00:12:43,170 --> 00:12:47,910 So the first thing is Vin where are you are the target from. 174 00:12:47,910 --> 00:12:49,360 I'm going to say set. 175 00:12:49,610 --> 00:12:57,630 We will talk more about self with as you can see silf is the view controller self refers to the class 176 00:12:57,630 --> 00:13:03,460 that you are programming on and most often when you yourself you mean the view controller. 177 00:13:03,480 --> 00:13:05,700 Not always but most often. 178 00:13:05,700 --> 00:13:07,320 You mean the view controller. 179 00:13:07,530 --> 00:13:15,420 So I'm saying there is a target in here in this implementation to end in this far part. 180 00:13:15,450 --> 00:13:20,550 There is a function I want you to call this thing so what's the name of that action. 181 00:13:20,550 --> 00:13:22,270 So let me make that action. 182 00:13:22,470 --> 00:13:27,780 That action is where it change the label. 183 00:13:27,920 --> 00:13:28,500 Right. 184 00:13:28,800 --> 00:13:35,340 So I'm say I selector change laborer's again. 185 00:13:35,640 --> 00:13:36,800 What is a selector. 186 00:13:36,800 --> 00:13:39,770 We'll come back with in in a few lessons from now. 187 00:13:39,780 --> 00:13:44,550 But for now you need to learn that whenever you want to call an action you need to get a selector to 188 00:13:44,550 --> 00:13:45,570 that action. 189 00:13:45,570 --> 00:13:52,830 So I'm going to say Action selector change label get this label this change labor function and then 190 00:13:52,920 --> 00:14:02,280 saying what type of events the event I want to use is UI control events tuckshop inside just events 191 00:14:02,850 --> 00:14:04,400 touch up inside. 192 00:14:04,500 --> 00:14:08,530 Exactly the that you then we're using the interface builder. 193 00:14:08,640 --> 00:14:17,310 So to recap if you have the outgrowth of our bar then we say that but then our target team here look 194 00:14:17,310 --> 00:14:21,620 for a function through a selector called whatever you call that. 195 00:14:21,630 --> 00:14:29,020 In this case change label on the trigger it depending on a certain situation which is in your ears touch 196 00:14:29,020 --> 00:14:30,190 up inside. 197 00:14:30,510 --> 00:14:31,830 And what do we want to happen. 198 00:14:31,830 --> 00:14:36,420 We want to say label the hard text. 199 00:14:36,630 --> 00:14:43,340 This was for romantic that's about that. 200 00:14:43,350 --> 00:14:45,160 So I don't get those two. 201 00:14:45,810 --> 00:14:46,690 Let's move on thought 202 00:14:51,560 --> 00:14:52,750 on here. 203 00:14:52,850 --> 00:14:55,160 It shows up top on something. 204 00:14:55,160 --> 00:14:56,820 This was programmatic. 205 00:14:56,990 --> 00:15:03,860 So we saw essentially three different ways of connecting buttons and running you know functions with 206 00:15:03,860 --> 00:15:12,590 buttons one of them was a Baden's of what is true a c stands at itself. 207 00:15:13,230 --> 00:15:21,370 Another one was but or action is called from Interface Builder. 208 00:15:21,530 --> 00:15:27,540 And finally it was actions caused by that target. 209 00:15:27,560 --> 00:15:35,060 So three different ways of calling buttons and calling functions through buttons and this one add a 210 00:15:35,210 --> 00:15:39,010 lot of interactivity to everything that you are doing. 211 00:15:39,020 --> 00:15:41,140 So with that in mind let's move on to access.