我将tablerowactions更新为等效的swift 4,以便能够设置图标而不是文本,作为用户向左滑动表格元素时显示的按钮。我的问题是,如果用户从右向左滑动而不是仅显示所有可用的动作,则第一个定义的动作(在我的情况下为delete动作)会自动触发。我想停用此行为。
我的代码当前看起来像这样:

 override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .normal, title:  "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        // implemantion of delete-button here
        // ...

        success(true)
    })


    deleteAction.image = #imageLiteral(resourceName: "deleteIcon")
    deleteAction.backgroundColor = .red
    return UISwipeActionsConfiguration(actions: [deleteAction])
}

最佳答案

UISwipeActionsConfiguration具有允许您关闭此行为的属性performsFirstActionWithFullSwipe。 (Documentation)

所以代替:

return UISwipeActionsConfiguration(actions: [deleteAction])

做这样的事情:
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration

10-07 18:35