Welcome back again.
The default behavior of when you swipe over a sell off a table view is to show you one button and that
button is primarily used for deleting the cell.
If this doesn't I wish for you how to add multiple edit buttons.
So that's going to explode and I'm going to start a new application and I'm going to call this application
multiple edits by the NS app and this application is actually going to be a single view application
and I will add to my table view video in my view controller.
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
constraints for it at all missing constraints.
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
be the basic type and then I'm going to go ahead and say my table view has a boss its delegate and data
source set to the view controller.
So they're all being fed from here.
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
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
to head back into my storyboard select my view controller in the connections that it's her I'm going
to say my table view is this one.
So now everything is connected together as if this was a table view controller which is not in this
case I'm going to go back to my view controller and as you can remember for a situation like this we
need to conform to the UI table view data source as well as UI table view delegate and the moment we
do that we have to necessarily feed two methods into here.
So the first method I have to implement is number of rows in section.
I'm going to say just return a static value of ten at all times.
So I have ten cells in my table view and the other one is cell for a row at index path.
This is the other function that I must have.
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
this cell.
And the only thing in between is cell that text label that text shows a static value of a test.
So that's all I have to do in here.
I have to make sure that I have the two functions number of rows and a cell for role.
And now when we run the application we should be able to see 10 cells that they all say test just like
this one.
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
one of the cells.
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
view.
One of them is the one that we have done before can editorial at index spot and the return for that
is going to be returned true because we want to be able to edit this stuff.
The other one however is the edit actions for a row at parts.
I'm going to say edit actions for actions for role.
And this is the other function that essentially tells us of what what ends you want to see for each
of the rows.
And of course depending on the index mark you can customize it but for now I'm going to make it one
for all of them.
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.
So I'm going to say more by then.
Which is becoming UI table view row action.
I'm going to have to build the one using a site and a title and a handler.
So their style of it I'm going to go ahead and say Let it be the default the style.
The title of it.
I'm going to say more something like that and action for it which essentially is a closure.
I'm gonna say action and index parts.
And then here you can do whatever you think you want to be doing.
This essentially becomes the body of that button if in here you want to print something we could say
print something or call another function or whatever that you think you would need to do when that by
then gets pressed.
So let's go ahead and make another one.
I'm going to copy this whole thing.
Say this one is actually called delete by then.
So we had them more and we also have the delete and the delete button it says delete it has a question
mark and then what they could do is they could change the color of course of these I could go ahead
and say more by then dot background color becomes UI color that orange and I'm going to copy that for
the delete by then and say the delete button actually gets to be read that because that kind of makes
makes better sense.
We finally to return both of these and that is very important because here my function edit actions
for role it's expecting an array of you a table view role actions.
So I've got two of those so I'm gonna go ahead and say well return both of those and more and delete.
So I have an array of this button and this by then they both have some actions happening in them and
they're being returned.
For all of the index parts in this particular table view.
So let's run the application and if it all works well we should be able to see two bodies appearing
when we swipe each cell and they should correspond to whatever we ask them to be.
So now one of them is delete one of them is more.
Once again one of them is delete one of them is more.
And that is how you add multiple added buttons to your sets.
Let's keep it up to here and we'll move on to our next lesson.