override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
if condition == true {
let pause = UITableViewRowAction(style: .Destructive, title: "pause") { action, index in
print("pause button tapped")
return [pause]
}
} else {
return .None
}
}
This code didn't disable to swipe in cell. But when swipe the cell delete option appear. Please anyone can help to slove this problem.
最佳答案
您需要使用canEditRowAt
为此并根据您的条件返回 Bool
值。
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
if condition == true {
return true
}
return false
}
不需要在 editActionsForRowAtIndexPath
方法中检查条件。
关于swift - 如果条件在 swift 中为 false,则禁用在 tableView 中滑动单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42508060/