1

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

 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])
}
4

1 回答 1

2

UISwipeActionsConfiguration有一个属性可以让你关闭这个行为,叫做performsFirstActionWithFullSwipe. (文档

所以而不是:

return UISwipeActionsConfiguration(actions: [deleteAction])

做这样的事情:

let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration
于 2018-03-11T18:43:34.580 回答