What is the method to remove a custom cell from a UITableView?
Not sure why you want to do this instead of the normal delete behavior, but ...
First you need to know indexPath
for the cell this button is clicked on. So you have to wire the custom cell to get the button action and then call the table method indexPathForCell
on that cell to get the index table.
After that, you put the indexPath inside NSArray
and pass it to the table method deleteRowsAtIndexPaths
(and also choose the animation type to delete the cell). This will also call the dataSource method commitEditingStyle
so you can delete the underlying data as well.
Keep in mind that this way you bypass the two-step deletion process that is built into the table - where the user usually requests the delete and then has to confirm it. Therefore, for the sake of safety, you probably want to implement something like this.
Also, the default behavior for scrolling through a table cell is to invoke the delete button. You can override the delegate method editingStyleForRowAtIndexPath
and return UITableViewCellEditingStyleNone
for that cell, whatever it does by default.
a source to share