【发布时间】:2021-07-23 11:56:25
【问题描述】:
我正在尝试将滑动操作添加到我的表格视图中。当我使用简单的 tableview 数据源方法时,它运行良好(trailingSwipeActionsConfigurationForRowAt)。但是当我用 Diffable 数据源尝试同样的事情时,它甚至没有调用刷卡的方法。我使用断点进行跟进,但没有奏效。 我正在使用 swift 5 (UIKit)、Xcode 12.4
【问题讨论】:
我正在尝试将滑动操作添加到我的表格视图中。当我使用简单的 tableview 数据源方法时,它运行良好(trailingSwipeActionsConfigurationForRowAt)。但是当我用 Diffable 数据源尝试同样的事情时,它甚至没有调用刷卡的方法。我使用断点进行跟进,但没有奏效。 我正在使用 swift 5 (UIKit)、Xcode 12.4
【问题讨论】:
我通过以下方法解决了这个问题: 使用的 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 })
【讨论】: