1 00:00:00,330 --> 00:00:05,790 Now, what I like to do whenever I'm creating an app with something like a table view is I like to populate 2 00:00:05,790 --> 00:00:07,680 it with some dummy data. 3 00:00:07,680 --> 00:00:10,370 So I know that all my functions are working right. 4 00:00:10,830 --> 00:00:16,620 The danger of using Firebase for this whilst Firebase is fantastic, we don't know if we actually have 5 00:00:16,620 --> 00:00:17,830 the data streaming through. 6 00:00:18,180 --> 00:00:23,370 So if it doesn't show in the table view, you now have to go down this long rabbit hole of discovering 7 00:00:23,370 --> 00:00:28,080 what happened to the data and why the table view isn't doing what you need it to do. 8 00:00:29,400 --> 00:00:31,890 And as a developer, you go through that all the time. 9 00:00:32,340 --> 00:00:38,160 So what I like to do is take these very slow in small stages, which ironically is actually faster than 10 00:00:38,160 --> 00:00:40,080 just jumping on and doing everything at once. 11 00:00:40,530 --> 00:00:44,840 So what we're going to do here is get the cell for row at. 12 00:00:45,390 --> 00:00:52,170 So we are going to specify how what we're going to put in the cells and we're going to have the number 13 00:00:52,170 --> 00:00:53,370 of rows in section. 14 00:00:53,520 --> 00:00:57,000 And all we're going to do for that is going to return, let's say one hundred. 15 00:00:57,750 --> 00:00:59,820 We're just going to populate this with 100 rows. 16 00:01:00,330 --> 00:01:03,630 Then we're going to populate those hundred rows with some code. 17 00:01:04,380 --> 00:01:08,270 So I've got some code here that I'm just going to paste in. 18 00:01:08,280 --> 00:01:10,680 Feel free to pause and copy this if you need to. 19 00:01:11,730 --> 00:01:18,380 We're going to define our cell, which is a UI table view cell, by going to the table view and decoding 20 00:01:18,390 --> 00:01:23,120 a reusable cell with an identifier called Message Table View Cell. 21 00:01:23,490 --> 00:01:28,920 So I'm going to copy that identifier can go to the main storyboard and I'm going to tap this cell. 22 00:01:29,520 --> 00:01:35,760 Now, when you tap it, ensure that over here on the left, see what I'm tapping, it hasn't selected 23 00:01:35,760 --> 00:01:38,640 the content view you need to select the cell. 24 00:01:38,880 --> 00:01:43,020 OK, so storyboards in Xcode are notorious for doing this. 25 00:01:43,020 --> 00:01:50,400 As far as I'm concerned, you usually select the wrong thing over here on the right side in the reuse 26 00:01:50,400 --> 00:01:51,210 identifier. 27 00:01:51,930 --> 00:01:54,260 Just drop a paste into there and hit enter. 28 00:01:54,540 --> 00:01:57,320 And now we have the cell defined. 29 00:01:57,690 --> 00:02:04,890 So if I hit play on this, while it's not going to work because we haven't yet returned that cell, 30 00:02:05,880 --> 00:02:10,830 but now if I hit play on the iPod Touch, it's not going to populate the cell. 31 00:02:10,830 --> 00:02:12,960 It's not going to do anything particular with it. 32 00:02:13,200 --> 00:02:17,610 It's just we're just making sure that this cell can be grabbed. 33 00:02:17,910 --> 00:02:18,260 OK. 34 00:02:20,230 --> 00:02:26,440 And there we have it, so we have 100 cells, and if I just scroll, we're left with the bog standard 35 00:02:26,440 --> 00:02:30,250 text title and subtitle until we get all the way to the bottom. 36 00:02:30,790 --> 00:02:33,070 And, of course, all the way to the top. 37 00:02:35,100 --> 00:02:41,160 OK, so we know that all works now stop that running so it doesn't mess up my Mac, what are we going 38 00:02:41,160 --> 00:02:41,790 to do now? 39 00:02:41,940 --> 00:02:46,830 Well, let's see what the other code is here while I've got this message which will get on to you when 40 00:02:46,830 --> 00:02:48,300 we get to the firebase part. 41 00:02:48,330 --> 00:02:49,530 Got a message content. 42 00:02:50,610 --> 00:02:59,100 And we have some other items here, so I think what we're going to do for these particular items is 43 00:02:59,100 --> 00:03:05,210 leave that until we get to the firebase part of this, because this is all firebase related. 44 00:03:06,270 --> 00:03:11,490 If we weren't using Firebase, the relevant lines, for your information would be this one and this 45 00:03:11,490 --> 00:03:11,700 one. 46 00:03:12,090 --> 00:03:16,260 OK, and if you had a custom cell, then you wouldn't have detailed or text. 47 00:03:16,260 --> 00:03:19,230 You'd have the particular things that you'd created in the cell. 48 00:03:20,100 --> 00:03:23,100 OK, now we do need to copy this. 49 00:03:23,100 --> 00:03:25,050 Did select row at. 50 00:03:25,530 --> 00:03:34,530 OK, so instead of copying it, what I'm going to do is just type did select row at because that old 51 00:03:34,530 --> 00:03:37,980 code is fairly old and something might have changed. 52 00:03:39,100 --> 00:03:41,880 And what we're going to do here is get our table view. 53 00:03:42,810 --> 00:03:49,680 You see now it's bringing up the table view in this method or the table view in the class. 54 00:03:50,100 --> 00:03:52,410 And it's really difficult to tell which is which. 55 00:03:52,770 --> 00:03:54,960 I believe it's this top one. 56 00:03:56,610 --> 00:04:02,630 We'll see, though, although in theory it doesn't matter because they are the same thing. 57 00:04:05,040 --> 00:04:18,600 So we want the deselect row at the index path that we've passed in and animated, let's have true because 58 00:04:18,600 --> 00:04:23,480 as things stand, if I tap the row that gray bastard's stuck on. 59 00:04:23,910 --> 00:04:27,760 But as long as we have this deselect row, the gray bar will go away. 60 00:04:28,110 --> 00:04:30,900 So whilst that's loading, let's see what else we've got to do here. 61 00:04:31,620 --> 00:04:37,150 We can specify the number of sections which we don't have to do. 62 00:04:37,360 --> 00:04:41,580 There's our deselect working, but I find it helps. 63 00:04:43,710 --> 00:04:44,720 What does it help with? 64 00:04:45,180 --> 00:04:50,700 It helps to have a full set of the table view functions I use most often and then I just copy that over 65 00:04:50,700 --> 00:04:51,960 between applications. 66 00:04:52,110 --> 00:04:55,710 So I know that I'm tackling all the things that I need to tackle. 67 00:04:57,390 --> 00:05:02,940 So if we get a number of sections in the table view, we can just return one. 68 00:05:03,360 --> 00:05:09,390 Now, clearly we don't need this right now because it by default it goes to one. 69 00:05:10,020 --> 00:05:17,280 But later on in your app, you might actually want to separate your table, your rows out into sections, 70 00:05:17,490 --> 00:05:19,450 in which case you would have to update that. 71 00:05:19,980 --> 00:05:22,650 OK, so that's our table view working. 72 00:05:22,860 --> 00:05:30,060 That's how we set the delegates and that's how we implement all the table view functions.