/ / Glissement sur UITableViewCell - swift, xcode, swift3, tableview, cell

Balayage sur UITableViewCell - swift, xcode, swift3, tableview, cell

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = UIColor.lightGray

let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
print("favorite button tapped")
}
favorite.backgroundColor = UIColor.orange

let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
print("share button tapped")
}
share.backgroundColor = UIColor.blue

return [share, favorite, more]
}

J'ai insérer ce code pour créer des actions à effectuer sur un seul Cell, mais lorsque je lance le projet et que j'essaie de glisser sur une cellule, la seule action possible est Delete.

Comment puis-je résoudre ce problème?

Réponses:

2 pour la réponse № 1

Signature de tableView(_:editActionsForRowAt:) est modifié dans Swift 3 pour aimer ci-dessous. Alors remplacez simplement votre editActionsForRowAt avec en dessous d'un.

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = UIColor.lightGray

let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
print("favorite button tapped")
}
favorite.backgroundColor = UIColor.orange

let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
print("share button tapped")
}
share.backgroundColor = UIColor.blue

return [share, favorite, more]
}