i have a custom cell i want to delete it when a button is clicked situated on the custom cell itself.how do i achieve this. someone help i am stuck at this from many days
Not sure why you want to do this instead of using the standard delete behavior, but...
First you need to know the indexPath
for the cell on which that button is being pressed. So you have to wire the custom cell to receive the button action, and then call the table's indexPathForCell
method with that cell to get the indexPath.
Once you have it, you put the indexPath inside an NSArray
and pass it to the table's deleteRowsAtIndexPaths
method (and also choose the type of animation for removing the cell). This will also invoke the dataSource's commitEditingStyle
method to let you delete the underlying data as well.
Keep in mind that by doing it this way, you're bypassing the two-step delete process that is built into the table -- where the user would normally request a delete and then have to confirm it. So for the sake of safety, you'll probably want to implement something like that yourself.
Also, the default behavior for swiping across a table cell is to bring up the delete button. You may want to override the editingStyleForRowAtIndexPath
delegate method and return UITableViewCellEditingStyleNone
for that cell so it doesn't do the default thing.