1 00:00:00,540 --> 00:00:01,560 Welcome back again. 2 00:00:01,560 --> 00:00:07,620 The default behavior of when you swipe over a sell off a table view is to show you one button and that 3 00:00:07,620 --> 00:00:10,710 button is primarily used for deleting the cell. 4 00:00:10,790 --> 00:00:14,560 If this doesn't I wish for you how to add multiple edit buttons. 5 00:00:14,610 --> 00:00:19,890 So that's going to explode and I'm going to start a new application and I'm going to call this application 6 00:00:20,430 --> 00:00:28,350 multiple edits by the NS app and this application is actually going to be a single view application 7 00:00:28,380 --> 00:00:32,490 and I will add to my table view video in my view controller. 8 00:00:32,530 --> 00:00:38,910 So I'm going to go in here say I have a table view which is exactly up there I'm going to add all the 9 00:00:38,910 --> 00:00:42,140 constraints for it at all missing constraints. 10 00:00:42,210 --> 00:00:50,220 I will also have a cell for it this cell as usual I'm going to give it a cell I.D. and it's going to 11 00:00:50,220 --> 00:00:57,470 be the basic type and then I'm going to go ahead and say my table view has a boss its delegate and data 12 00:00:57,480 --> 00:01:00,000 source set to the view controller. 13 00:01:00,270 --> 00:01:02,190 So they're all being fed from here. 14 00:01:02,430 --> 00:01:07,530 And finally I'm going to have to add an outlet for my table view so I'm going to come in here and say 15 00:01:07,620 --> 00:01:16,050 at a B outlet I'm going to say valuable my table view because of the type of UI table view I don't want 16 00:01:16,050 --> 00:01:22,020 to head back into my storyboard select my view controller in the connections that it's her I'm going 17 00:01:22,020 --> 00:01:24,750 to say my table view is this one. 18 00:01:24,750 --> 00:01:30,390 So now everything is connected together as if this was a table view controller which is not in this 19 00:01:30,390 --> 00:01:35,940 case I'm going to go back to my view controller and as you can remember for a situation like this we 20 00:01:35,940 --> 00:01:45,000 need to conform to the UI table view data source as well as UI table view delegate and the moment we 21 00:01:45,000 --> 00:01:48,810 do that we have to necessarily feed two methods into here. 22 00:01:49,110 --> 00:01:54,880 So the first method I have to implement is number of rows in section. 23 00:01:54,880 --> 00:01:59,400 I'm going to say just return a static value of ten at all times. 24 00:01:59,400 --> 00:02:05,070 So I have ten cells in my table view and the other one is cell for a row at index path. 25 00:02:05,070 --> 00:02:07,650 This is the other function that I must have. 26 00:02:07,800 --> 00:02:17,460 And for this I'm going to say let's cell B table view D Q reusing cell I.D. And I'm going to say return 27 00:02:17,580 --> 00:02:18,630 this cell. 28 00:02:18,730 --> 00:02:26,280 And the only thing in between is cell that text label that text shows a static value of a test. 29 00:02:26,580 --> 00:02:28,610 So that's all I have to do in here. 30 00:02:28,620 --> 00:02:33,820 I have to make sure that I have the two functions number of rows and a cell for role. 31 00:02:33,900 --> 00:02:39,780 And now when we run the application we should be able to see 10 cells that they all say test just like 32 00:02:39,780 --> 00:02:40,480 this one. 33 00:02:40,650 --> 00:02:46,020 And now the next thing you want to do is we want to be able to see more than one by then when we swipe 34 00:02:46,020 --> 00:02:47,190 one of the cells. 35 00:02:47,250 --> 00:02:53,910 So to do that I'm going to go ahead in here but I have to add two functions or two methods of my table 36 00:02:53,910 --> 00:02:54,380 view. 37 00:02:54,450 --> 00:03:00,870 One of them is the one that we have done before can editorial at index spot and the return for that 38 00:03:00,900 --> 00:03:05,810 is going to be returned true because we want to be able to edit this stuff. 39 00:03:05,940 --> 00:03:10,380 The other one however is the edit actions for a row at parts. 40 00:03:10,380 --> 00:03:17,370 I'm going to say edit actions for actions for role. 41 00:03:17,520 --> 00:03:23,970 And this is the other function that essentially tells us of what what ends you want to see for each 42 00:03:24,060 --> 00:03:24,770 of the rows. 43 00:03:24,780 --> 00:03:29,880 And of course depending on the index mark you can customize it but for now I'm going to make it one 44 00:03:29,880 --> 00:03:30,960 for all of them. 45 00:03:31,020 --> 00:03:36,510 So I'm going to say let and the first thing I want to do is I want to have a button that says more. 46 00:03:36,840 --> 00:03:38,330 So I'm going to say more by then. 47 00:03:38,340 --> 00:03:43,080 Which is becoming UI table view row action. 48 00:03:43,230 --> 00:03:47,610 I'm going to have to build the one using a site and a title and a handler. 49 00:03:47,640 --> 00:03:52,740 So their style of it I'm going to go ahead and say Let it be the default the style. 50 00:03:52,800 --> 00:03:53,850 The title of it. 51 00:03:53,880 --> 00:04:00,770 I'm going to say more something like that and action for it which essentially is a closure. 52 00:04:00,780 --> 00:04:04,830 I'm gonna say action and index parts. 53 00:04:05,190 --> 00:04:08,550 And then here you can do whatever you think you want to be doing. 54 00:04:08,550 --> 00:04:14,310 This essentially becomes the body of that button if in here you want to print something we could say 55 00:04:14,640 --> 00:04:22,090 print something or call another function or whatever that you think you would need to do when that by 56 00:04:22,090 --> 00:04:23,310 then gets pressed. 57 00:04:23,340 --> 00:04:24,830 So let's go ahead and make another one. 58 00:04:24,840 --> 00:04:26,320 I'm going to copy this whole thing. 59 00:04:26,400 --> 00:04:29,430 Say this one is actually called delete by then. 60 00:04:29,460 --> 00:04:36,810 So we had them more and we also have the delete and the delete button it says delete it has a question 61 00:04:36,810 --> 00:04:42,030 mark and then what they could do is they could change the color of course of these I could go ahead 62 00:04:42,030 --> 00:04:51,150 and say more by then dot background color becomes UI color that orange and I'm going to copy that for 63 00:04:51,150 --> 00:04:57,240 the delete by then and say the delete button actually gets to be read that because that kind of makes 64 00:04:57,300 --> 00:04:58,670 makes better sense. 65 00:04:58,860 --> 00:05:06,110 We finally to return both of these and that is very important because here my function edit actions 66 00:05:06,110 --> 00:05:12,080 for role it's expecting an array of you a table view role actions. 67 00:05:12,080 --> 00:05:20,290 So I've got two of those so I'm gonna go ahead and say well return both of those and more and delete. 68 00:05:20,330 --> 00:05:27,710 So I have an array of this button and this by then they both have some actions happening in them and 69 00:05:27,710 --> 00:05:28,820 they're being returned. 70 00:05:28,820 --> 00:05:32,520 For all of the index parts in this particular table view. 71 00:05:32,660 --> 00:05:38,360 So let's run the application and if it all works well we should be able to see two bodies appearing 72 00:05:38,360 --> 00:05:43,070 when we swipe each cell and they should correspond to whatever we ask them to be. 73 00:05:43,070 --> 00:05:45,480 So now one of them is delete one of them is more. 74 00:05:45,590 --> 00:05:48,190 Once again one of them is delete one of them is more. 75 00:05:48,340 --> 00:05:52,760 And that is how you add multiple added buttons to your sets. 76 00:05:52,790 --> 00:05:56,000 Let's keep it up to here and we'll move on to our next lesson.