I need to turn on a tableView editing mode by clicking on one of its cells from swipe action "move":
Code for swipe action:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let move = UIContextualAction(style: .normal, title: "Переместить") { (action, view, completionHandler) in
self.turnEditing()
completionHandler(true)
}
move.backgroundColor = UIColor(named: "CalmBlueColor")
let configuration = UISwipeActionsConfiguration(actions: [move])
return configuration
}
turnEditing() function:
func turnEditing() {
if tableView.isEditing {
tableView.isEditing = false
} else {
tableView.isEditing = true
}
}
When I press on the swipe actions it's just closes, without going to editing mode... Here is the GIF: https://cln.sh/ilEN9F
Is it possible to go into editing mode from a swipe action or only from a barButtonItem + IBAction?
I think I found the cause:
Add this print:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let move = UIContextualAction(style: .normal, title: "Переместить") { (action, view, completionHandler) in
print("before", tableView.isEditing)
self.turnEditing()
tableView.isEditing.toggle() // <<-- toggle again, or just call self.turnEditing() a second time !!!!!
completionHandler(true)
}
move.backgroundColor = UIColor(named: "CalmBlueColor")
let configuration = UISwipeActionsConfiguration(actions: [move])
return configuration
}
You get
- before true
So that means that isEditing is set true (probably with an internal property) when entering in the handler.
Hence, when calling
self.turnEditing()
you turn it off !!!! Calling a second time will turn on.
How can I send this question as a bug report?
- For a question, click
Contact us
at the bottom of this page Contact Us. https://developer.apple.com/contact/ - For a bug report, click
Feedback and bug reporting
https://developer.apple.com/bug-reporting/