[英]iOS - disable right or left swipe for UITableViewCell
I have implemented iOS 11 trailingSwipeActionsConfigurationForRowAt
and leadingSwipeActionsConfigurationForRowAt
for my UITableViewCell.我已经为我的 UITableViewCell 实现了 iOS 11
trailingSwipeActionsConfigurationForRowAt
和leadingSwipeActionsConfigurationForRowAt
。 I'm using trailingSwipeActionsConfigurationForRowAt
to disable the row, and leadingSwipeActionsConfigurationForRowAt
to undo the disable of the row.我正在使用
trailingSwipeActionsConfigurationForRowAt
来禁用该行,并使用leadingSwipeActionsConfigurationForRowAt
来撤消该行的禁用。 I've tried to use canEditRowAt
, but this disables editing of the entire row.我尝试使用
canEditRowAt
,但这会禁用整行的编辑。 Is there a way to disable only one of the swipe actions instead of disabling the entire row from editing?有没有办法只禁用一个滑动操作而不是禁用整行编辑?
I want to disable the undo swipe action if I already swiped to undo, but enable the cancel swipe action.如果我已经滑动以撤消,我想禁用撤消滑动操作,但启用取消滑动操作。 I also want to disable the cancel swipe action if I already swiped to cancel, but enable the undo swipe action.
如果我已经滑动取消,我还想禁用取消滑动操作,但启用撤消滑动操作。
Try to return the empty array of actions in trailingSwipeActionsConfigurationForRowAt
method to disable one sided action.尝试在
trailingSwipeActionsConfigurationForRowAt
方法中返回空的动作数组以禁用单侧动作。
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let swipeAction = UISwipeActionsConfiguration(actions: [])
return swipeAction
}
Returning nil is sufficient to prevent the swipe action.返回 nil 足以防止滑动操作。
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return nil
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.