简体   繁体   English

响应取消 UISwipeActionsConfiguration

[英]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.我的视图控制器需要跟踪 UISwipeAction 当前是否处于活动状态,因为在滑动操作期间不应允许编辑。 To achieve that I use a flag which is set back to default in the only UIContextualAction, which removes the row.为了实现这一点,我在唯一的 UIContextualAction 中使用了一个设置回默认值的标志,它删除了该行。 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?有没有办法在这样取消操作时收到通知?

I've found the answer which is actually quite simple: didEndEditingRow will be notified once you tapped to dismiss the swipe action.我找到了实际上很简单的答案:一旦您点击以关闭滑动操作,就会通知didEndEditingRow

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM