In my tableview, I only want certain cells to be able to drag to the left for some options based on a condition. The other cells should behave as if commitEditingStyle
is disabled. Is this possible?
With the code below, I can add the actions when the conditions are met but the other cells still get the default "delete" action. How do I get rid of that delete action?
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let object = items[indexPath.row]
if object.name == "name" {
// someAction
var addAction = UITableViewRowAction(style: .Default, title: "+") { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
}
return [addAction]
}
return nil
}
With the code below I managed to enable and disable the actions. But only with the Delete
button.
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
let object = items[indexPath.row]
if object.name == "joyce" {
return UITableViewCellEditingStyle.Delete
} else {
return UITableViewCellEditingStyle.None
}
}