TrailingSwipeAction:如何在滑动时停用自动删除?
TrailingSwipeAction: How to deactivate auto delete on swipe through?
我将我的 tablerowactions 更新为 swift 4 等效于能够设置图标而不是文本作为用户在 table 上向左滑动时显示的按钮元素。我的问题是,如果用户从右向左滑动而不是仅显示所有可用操作,则第一个定义的操作(在我的例子中是删除操作)会自动触发。我想停用此行为。
我的代码目前看起来像这样:
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
我将我的 tablerowactions 更新为 swift 4 等效于能够设置图标而不是文本作为用户在 table 上向左滑动时显示的按钮元素。我的问题是,如果用户从右向左滑动而不是仅显示所有可用操作,则第一个定义的操作(在我的例子中是删除操作)会自动触发。我想停用此行为。 我的代码目前看起来像这样:
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