2

I have an UITableView that I manage in a controller with UITableViewDelegate and UITableViewDataSource. In this table I have a custom cell, the problem is that the function editActionsForRowAtIndexPath gets called only sometimes (maybe when I swype in a particular way, I don't know), my code is the following:

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let doneAction: UITableViewRowAction
    //let highlightAction: UITableViewRowAction
    if(self.compiti[indexPath.row].completato){
        doneAction = UITableViewRowAction(style: .Normal, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            let compito = self.compiti[indexPath.row]
            self.db.contrassegnaCompito(compito)
            UITableViewRowAction
       }
        doneAction.backgroundColor = UIColor.redColor()
    }else{
        doneAction = UITableViewRowAction(style: .Normal, title: "Fatto") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            let compito = self.compiti[indexPath.row]
            self.db.contrassegnaCompito(compito)
        }
        doneAction.backgroundColor = UIColor(red: 67/255, green: 160/255, blue: 71/255, alpha: 0.7)
    }
    return [doneAction]
}
D4ttatraya
  • 3,344
  • 1
  • 28
  • 50
Zac
  • 423
  • 1
  • 6
  • 18

2 Answers2

3

you need to add this method implementation as well or you won't be able to swipe to display the actions

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    // it can be empty
}
zepar
  • 155
  • 7
0

It works for me with this code, try starting from this and you will probably find when the problem occurs

 func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    var doneAction :UITableViewRowAction!

    doneAction = UITableViewRowAction(style: .Default, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            UITableViewRowAction
    }
    return [doneAction]
}
Mat Grlt
  • 131
  • 8
  • Still no action, i think that there is something else maybe in my cell that is "capturing" the action... – Zac Sep 12 '16 at 15:27