Accessing the editing detail button of UITableViewCell

I've got a UITableViewCell that is in a TableView that is in editing mode. I have the cell's editing accent set to the Detail option. How can I access that little circle detail button that appears when my table view goes into editing mode, so that I can add a target to it?

Answered by OOPer in 336717022

You usually do not and should not access the accessory button of a table view cell.


When you want to invoke some code when the accessory button is tapped, you implement a method defined in UITableViewDelegate.


func tableView(UITableView, accessoryButtonTappedForRowWith: IndexPath)


func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    //...
}

Do you want to add a target (why?, target is the tableView itself) or an action ?


That's not needed for adding action.


When you want to edit (delete row or move row with drag and drop), set the tableView:


table.isEditing = true


the red minus button ➖ shows.


The Action is then defined in


     func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
      
        if editingStyle == .delete {
          // Do what's appropriate
        }

     // then return editingMode to false
     table..isEditing = false
}
Accepted Answer

You usually do not and should not access the accessory button of a table view cell.


When you want to invoke some code when the accessory button is tapped, you implement a method defined in UITableViewDelegate.


func tableView(UITableView, accessoryButtonTappedForRowWith: IndexPath)


func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    //...
}
Accessing the editing detail button of UITableViewCell
 
 
Q