nontomatic
nontomatic

Reputation: 2043

Respond to canceling of UISwipeActionsConfiguration

My view controller needs to keep track whether a UISwipeAction is currently active as editing should not be allowed during a swipe action. To achieve that I use a flag which is set back to default in the only UIContextualAction, which removes the row. This works fine:

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {  
  isTrailingSwipeActionActive = true

  let removeAction = UIContextualAction(style: .destructive, title: nil) { (action, iconView, completionHandler) in
    self.isTrailingSwipeActionActive = false

    completionHandler(true)
  }
}

But when the swipe action is cancelled by tapping on the row again while the contextual action is showing (the cell animates back into normal state), obviously the remove action is not triggered and my flag isn't set back.

Is there a way to be notified when the action is cancelled like that?

Upvotes: 3

Views: 499

Answers (1)

nontomatic
nontomatic

Reputation: 2043

I've found the answer which is actually quite simple: didEndEditingRow will be notified once you tapped to dismiss the swipe action.

override func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
  isTrailingSwipeActionActive = false
}

Upvotes: 1

Related Questions