UITableViewRowAction 动作在滑动时触发,而不是在点击时触发
UITableViewRowAction action is triggered on swipe instead on tap
我不确定我是否理解正确,这里的文档有点混乱,但是在 UITableView 委托的主体中给出了以下代码:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let action = UITableViewRowAction(style: UITableViewRowAction.Style.normal,
title: "Do Something!") { (_, indexPath) in
self.doSomething()
}
return [action]
}
在 模拟器中 完成 "Do Something!" 按钮旁边的向左滑动操作后,将执行对 doSomething()
方法的调用。
我不希望调用执行两次。是我的配置有问题还是我没有理解UITableViewRowAction
的目的?
TLDR:我希望仅在点击出现的按钮时触发滑动动作回调。
谢谢。
要防止这种行为,您需要实施新的 iOS.
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let myAction = UIContextualAction(style: .someStyle, title: "Some tilte") { (action, sourceView, completionHandler) in
print("action has been triggered")
completionHandler(true)
}
let preventSwipeFullAction = UISwipeActionsConfiguration(actions: [myAction ])
preventSwipeFullAction .performsFirstActionWithFullSwipe = false // set false to disable full swipe action
return preventSwipeFullAction
}
TableView Trailing Swipe Action
记住 tableView.isEditing
需要 false
才能调用 trailingSwipeActionsConfigurationForRowAt
。
completionHandler(true)
// passing true enable handler call action
我不确定我是否理解正确,这里的文档有点混乱,但是在 UITableView 委托的主体中给出了以下代码:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let action = UITableViewRowAction(style: UITableViewRowAction.Style.normal,
title: "Do Something!") { (_, indexPath) in
self.doSomething()
}
return [action]
}
在 模拟器中 完成 "Do Something!" 按钮旁边的向左滑动操作后,将执行对 doSomething()
方法的调用。
我不希望调用执行两次。是我的配置有问题还是我没有理解UITableViewRowAction
的目的?
TLDR:我希望仅在点击出现的按钮时触发滑动动作回调。
谢谢。
要防止这种行为,您需要实施新的 iOS.
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let myAction = UIContextualAction(style: .someStyle, title: "Some tilte") { (action, sourceView, completionHandler) in
print("action has been triggered")
completionHandler(true)
}
let preventSwipeFullAction = UISwipeActionsConfiguration(actions: [myAction ])
preventSwipeFullAction .performsFirstActionWithFullSwipe = false // set false to disable full swipe action
return preventSwipeFullAction
}
TableView Trailing Swipe Action
记住 tableView.isEditing
需要 false
才能调用 trailingSwipeActionsConfigurationForRowAt
。
completionHandler(true)
// passing true enable handler call action