editActionsForRowAtIndexPath was called but no action button is shown when the UITableViewCell is slided

1.8k Views Asked by At

I implemented editActionsForRowAtIndexPath and commitEditingStyle the swipe is working but no action buttons are shown on the UITableViewCell

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {  

    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in  
          // I did some work here  
    })  

    return [deleteAction]  
}  

Does anyone have an idea how to get the action buttons to show when sliding? (Currently, the cell slides but behind it is a white background with no action buttons. Also clicking this white background provokes no response of any kind)

Note: I implemented editActionsForRowAtIndexPath in another ViewController and it works. (The action buttons both appear and response to click events)

3

There are 3 best solutions below

0
On

commitEditingStyle is empty because it is required for sliding. editActionsForRowAtIndexPath is implemented and this works in one viewController but does not work for another

The code is as follow

 func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    }


func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        //some code here
    })


    return [deleteAction]
}
0
On

The event should be commitEditingStyle here to use swipe button actions

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if (editingStyle == UITableViewCellEditingStyle.Delete) {
            // handle delete (by removing the data from your array and updating the tableview)
        }
}
0
On

I had the same problem and in my case I realized that my custom cell was way to wide for the table view. I noticed this because the accessory was not shown. Once I ran it on the iPad Emulator, I saw the buttons.