1 00:00:00,770 --> 00:00:01,820 Welcome back again. 2 00:00:01,820 --> 00:00:08,630 This lesson is going to be a very simple lesson we learn how to use a pull refresh control to refresh 3 00:00:08,630 --> 00:00:10,030 the content of a table view. 4 00:00:10,400 --> 00:00:12,530 So I'm going to school in here. 5 00:00:12,530 --> 00:00:14,330 I'm going to add a new application. 6 00:00:14,330 --> 00:00:17,240 I'm going to call it table view. 7 00:00:17,300 --> 00:00:20,850 I think that table view refresh control. 8 00:00:21,420 --> 00:00:26,330 And again we have to do the basic stuff what I'm going to try to do them as quickly as they can in their 9 00:00:26,330 --> 00:00:27,110 storyboard. 10 00:00:27,110 --> 00:00:28,750 I don't have this file. 11 00:00:29,240 --> 00:00:32,200 Instead I have an actual table view controller. 12 00:00:32,330 --> 00:00:37,490 My table view controller has a cell that has an I.D. called Cell I.D.. 13 00:00:37,910 --> 00:00:38,980 It is basic. 14 00:00:38,990 --> 00:00:48,260 This is the initial view controller and I do have a class for it called my table view controller which 15 00:00:48,320 --> 00:00:55,100 in this storyboard is connected to here is all the things that we have done so many times so far and 16 00:00:55,100 --> 00:00:58,510 I'm trying to get through them as quickly as I can. 17 00:00:58,640 --> 00:01:09,290 And I have a valuable called my array which has only two cities in it Vancouver and New York and then 18 00:01:09,470 --> 00:01:14,740 in the number of the rows I have my array count. 19 00:01:14,870 --> 00:01:18,310 These are the only thing that matter in this particular application. 20 00:01:18,590 --> 00:01:26,960 And then I also have a cell for row that uses the cell a D doesn't need the index part because I'm not 21 00:01:26,960 --> 00:01:29,300 really using that for anything. 22 00:01:29,480 --> 00:01:36,440 I'm trying to cut down on the amount of code and come up with the simplest possible stuff and then they 23 00:01:36,440 --> 00:01:46,400 have to do in here is this I have to say cell that fixed table dot text becomes my array object that 24 00:01:46,400 --> 00:01:53,540 index part DOT rule and that's all I have to do to just show some stuff in my table view. 25 00:01:53,570 --> 00:01:58,610 Now this is something that we have done so many times before then new we want to happen in here is we 26 00:01:58,610 --> 00:02:05,690 want to be able to pull our people view using a UI refresh control and refresh the content of the table 27 00:02:05,690 --> 00:02:06,010 view. 28 00:02:06,380 --> 00:02:12,950 So to do that I'm going to go ahead and say I have a value event called My refresh control which is 29 00:02:12,950 --> 00:02:20,170 of the type you I refresh control and then of course I have to initialize it in my view did load. 30 00:02:20,200 --> 00:02:27,440 So in my view that Lord I'm going to go ahead and say My refresh control is a you I refresh control 31 00:02:27,950 --> 00:02:33,320 and then my refresh control essentially has to do something when it gets pulled. 32 00:02:33,350 --> 00:02:39,620 So we have to essentially add a target for it and I'm going to say add the target on the target for 33 00:02:39,620 --> 00:02:48,470 it is this I'm gonna go ahead and say at Target within self and the action for it is selector let's 34 00:02:48,470 --> 00:02:58,310 find an action for it I'm going to add something for it call it function refresh function and then it 35 00:02:58,310 --> 00:03:07,010 is called fine Shen then it is called is gonna call that one for the White event obviously that value 36 00:03:07,040 --> 00:03:14,960 changed value changed so when the refresh controller gets pulled it has to essentially call this one 37 00:03:15,530 --> 00:03:17,330 now I still have to do two things. 38 00:03:17,330 --> 00:03:23,090 One of them is to get rid of the error I have to say this is an art objective c kind of function so 39 00:03:23,090 --> 00:03:29,900 it exposes the selector and the other thing is we have made the refresh control but we haven't really 40 00:03:29,950 --> 00:03:37,820 added this to anyone and for that I'm going to go ahead and say self dot table view dot the sub view 41 00:03:38,030 --> 00:03:44,210 and I'm going to add the refresh control as a sub view to my table view to my table view will have that 42 00:03:44,780 --> 00:03:51,450 rotating you know bar that shows our study is being refreshed at the time the last thing that we're 43 00:03:51,470 --> 00:03:58,460 doing here before I can do an actual test with new data is once we come to the refresh control and we 44 00:03:58,460 --> 00:04:05,240 deal with the refresh or whatever we're trying to do when I'm going to do in here is it say self doubt 45 00:04:05,270 --> 00:04:14,080 table view data reload the data and then also my refresh control we have to and refreshing. 46 00:04:14,440 --> 00:04:16,280 So let's go ahead and run this application. 47 00:04:16,310 --> 00:04:23,210 He doesn't really do anything right now but he's gonna show us visually how refresh control works once 48 00:04:23,240 --> 00:04:30,590 we know that we can actually add extra data to our table view array as well so we now have this table 49 00:04:30,590 --> 00:04:37,400 view and if we pull it we can see the refresh happening up there it doesn't stay there for a very long 50 00:04:37,400 --> 00:04:44,000 time but it shows us that it is refreshing itself now the refresh usually happens when you are trying 51 00:04:44,000 --> 00:04:48,410 to pull new information from a network or somewhere. 52 00:04:48,440 --> 00:04:54,740 So because of that I'm going to actually try to simulate that even though this isn't a very good way 53 00:04:54,740 --> 00:05:03,030 of doing it but I'm going to say my array not append lets up and the few new cities to say I have a 54 00:05:03,030 --> 00:05:08,370 new city this one and I'm going to have another one. 55 00:05:08,370 --> 00:05:15,720 Let's say that is going to be real and then I'm going to go ahead and say even let's let's talk details 56 00:05:15,720 --> 00:05:19,800 about this I'm going to say my array dot sort them as well. 57 00:05:19,830 --> 00:05:25,200 So by now then the refresh happens some new information appears. 58 00:05:25,200 --> 00:05:31,350 Like I said this is a process that usually happens through a network and you will have to wait for the 59 00:05:31,350 --> 00:05:37,080 network to finish its work using a completion block and victim the completion block. 60 00:05:37,080 --> 00:05:43,390 We often actually run the table view reload and refresh control if we wait for those to happen. 61 00:05:43,420 --> 00:05:48,120 We will see more of these when we talk about networking in a few sections from now. 62 00:05:48,120 --> 00:05:54,240 But for now every time that we refresh it has to add the two new cities sort everything reload table 63 00:05:54,240 --> 00:05:56,310 view and end the refresh. 64 00:05:56,400 --> 00:05:57,860 Let's see that. 65 00:05:57,870 --> 00:05:59,040 Yes. 66 00:05:59,060 --> 00:06:05,220 And once again it does the same thing obviously it keeps adding new Delhi and Rio because every time 67 00:06:05,220 --> 00:06:09,470 it comes in here and appends to them it doesn't know that they already exist in there. 68 00:06:09,870 --> 00:06:17,850 So that's a very simple refresh contour for a table view used primarily when your data changes depending 69 00:06:17,850 --> 00:06:20,040 on a network status. 70 00:06:20,070 --> 00:06:22,980 Let's keep it up to here and we'll move on to our next lesson.