我将我的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])
}
答案 0 :(得分:1)
UISwipeActionsConfiguration
有一个允许您关闭此行为的属性,称为performsFirstActionWithFullSwipe
。 (Documentation)
所以而不是:
return UISwipeActionsConfiguration(actions: [deleteAction])
做这样的事情:
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration