ios - 快速禁用表格 View 单元格中的滑动操作

标签 ios swift tableview

我已经为表格 View 单元格实现了滑动操作,它们是两个操作:AcceptReject

当我第一次滑动时它必须出现,如果我第二次滑动单元格它不应该打开。

单元格的滑动 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/

相关文章:

ios - Objective-C iPhone - 立即在 Safari 中打开 URL 并退出应用程序

swift - 如何在 Swift 中处理异步请求?

swift - 按日期快速排序我的 tableView

iOS:在 numberOfRowsInSection 中返回 2 个计数值

ios - 在 Swift 中对 Firebase 实时数据库数据进行排序

ios - 切换 ViewController 时的 UISwitch/UISlider 值

ios - 当音频设备添加到 AVCaptureSession 时,UIImpactFeedbackGenerator 不工作

ios - 每个循环后都有延迟的按钮图像阵列动画

ios - Swift URL.path 更改 utf-8 字符的编码

ios - Swift 2 - 在 Obj-C 中使用时的完成 block 语法