简体   繁体   English

为什么前导滑动动作也被复制为尾随动作?

[英]Why is the leading swipe action also duplicated as a trailing action?

I have implemented a leading swipe action ('Delete') on my tableView which for a reason I can't figure out is also appearing as a trailing swipe action. 我在tableView上实现了领先的滑动动作(“删除”),由于我不知道的原因,它也显示为尾随滑动动作。 See code below: 参见下面的代码:

func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) ->
    UISwipeActionsConfiguration? {
    let delete1 = deleteAction(at: indexPath)
    return UISwipeActionsConfiguration(actions: [delete1])
}

func deleteAction(at indexPath: IndexPath) -> UIContextualAction {
    let action = UIContextualAction(style: .destructive, title: "Delete") { (action, view, completion) in
        self.delete(at: indexPath)
    }
    return action
}

I used to have a trailing swipe action, but I deleted this function out completely. 我过去经常进行滑动操作,但是我完全删除了此功能。 When I change 'leadingSwipeActionsConfigurationForRowAt' to 'trailingSwipeActions...' then only the trailing swipe action appears. 当我将“ leadingSwipeActionsConfigurationForRowAt”更改为“ trailingSwipeActions ...”时,仅出现尾随滑动动作。 Be grateful if anyone could tell me what I've missed. 如果有人能告诉我我错过了什么,请多谢。 Thanks. 谢谢。 尾随滑动

领先刷卡

Use this code to prevent trailingSwipeAction() 使用此代码来防止trailingSwipeAction()

    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle
    {
        return .none
    }
  • or 要么
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        return UISwipeActionsConfiguration(actions: [])
    }

Because that is the default behaviour, when swipes are enabled. 因为这是默认行为,所以启用了滑动功能。 You can do something like this to disable swipes on the trailing side, if you want to implement the destructive delete action on the left only. 如果您只想在左侧实施破坏性删除操作,则可以执行以下操作来禁用尾端的滑动。

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
   return UISwipeActionsConfiguration(actions: [])
}

By passing an empty set of actions, the trailing swipe will disappear due to having 0 set of possible actions. 通过传递一组空动作,由于有0组可能的动作,尾随滑动将消失。

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

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