我已经为表格 View 单元格实现了滑动操作,它们是两个操作:Accept
和 Reject
。
当我第一次滑动时它必须出现,如果我第二次滑动单元格它不应该打开。
单元格的滑动 Action 必须处于禁用模式。
最佳答案
首先,您应该跟踪与您交互过的单元格的 indexPath。
private var disabledCellsIndexPath = [IndexPath]()
然后在配置滑动操作的方法中(this is the new iOS 11 API):
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal, title: "Action Title", handler: { _, _, completionHandler in
// DO WHAT YOU WANT HERE
// …
// This is where you specify that this specific cell should be 'disabled'
self?.disabledCellsIndexPath.append(indexPath)
completionHandler(true)
})
return UISwipeActionsConfiguration(actions: [action])
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return !disabledCellsIndexPath.contains(indexPath)
}
关于ios - 快速禁用表格 View 单元格中的滑动操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51302810/