【问题标题】:Is there any way to swipe to delete/ Add actions into cell in UITableview Diffable datasource?有没有办法在 UITableview Diffable 数据源中滑动删除/添加操作到单元格中?
【发布时间】:2021-07-23 11:56:25
【问题描述】:

我正在尝试将滑动操作添加到我的表格视图中。当我使用简单的 tableview 数据源方法时,它运行良好(trailingSwipeActionsConfigurationForRowAt)。但是当我用 Diffable 数据源尝试同样的事情时,它甚至没有调用刷卡的方法。我使用断点进行跟进,但没有奏效。 我正在使用 swift 5 (UIKit)、Xcode 12.4

【问题讨论】:

    标签: ios swift uikit swift5


    【解决方案1】:

    我通过以下方法解决了这个问题: 使用的 diffabled 数据源子类如下。

    class GrocDataSource: UITableViewDiffableDataSource <GrocListSections, Grocs> {
    override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        if indexPath.section == 0 || indexPath.section == 2 {
            return true
        } else {
            return false
        }
    }
    

    }

    在数据源中实现了这个类:

    datasource = GrocDataSource(tableView: grocTableView, cellProvider: { (tableView, indexPath, grocs) in
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "GrocNameCell", for: indexPath) as? GrocNameCell else {return UITableViewCell()}
    return cell })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多