I have a UITableView (iOS 9) I have implemented two actions with swipe (one is delete) I have an Edit button to enable edit mode (to reorder the rows)
For that, I implemented
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated:animated)
if (!isInSwipeDeleteMode) {
if (self.tableView.editing) {
metAJourPersonnes()
tableView.reloadData()
}
else {
tableView.reloadData()
}
}
}
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if (indexPath.row < personnes.count) {
return true
} else {
return false
}
}
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let pers = personnes[sourceIndexPath.row]
personnes.removeAtIndex(sourceIndexPath.row)
if (destinationIndexPath.row < personnes.count)
{
personnes.insert(pers, atIndex: destinationIndexPath.row)
} else {
personnes.append(pers)
}
tableView.reloadData()
}
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if (indexPath.row < personnes.count) {
return .Delete
} else {
return .None
}
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
print("Delete closure called")
self.tableView(tableView, commitEditingStyle: .Delete, forRowAtIndexPath: indexPath)
}
let modifyClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
print("More closure called")
self.performSegueWithIdentifier("modifPersonne", sender: indexPath)
}
let deleteAction = UITableViewRowAction(style: .Default, title: "Supprimer", handler: deleteClosure)
let modifyAction = UITableViewRowAction(style: .Normal, title: "Modifier", handler: modifyClosure)
return [deleteAction, modifyAction]
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
switch editingStyle {
case .Delete:
// Delete in the coreData base
personnes.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
default: break
}
}
Everything is working fine, but I want the edit mode just working for reordering. I don't want the red minus sign to appear, but I want to keep the swipe actions.
Is this possible? It seems that disabling delete in edit mode does disable the swipe to delete gesture.