ios - 有没有办法在 UITableview Diffable 数据源中滑动删除/添加操作到单元格中?
问题描述
我正在尝试将滑动操作添加到我的表格视图中。当我使用简单的 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 })
推荐阅读
- javascript - 全新的反应和困惑我如何从函数中省略一个项目并将一个按钮注入我的网格
- bitbucket-pipelines - 将 Bitbucket 管道工件上传到共享点
- android - 从 DetailFragment 按下返回箭头按钮返回 ThumbnailFragment 后,暴露的下拉菜单的 AutoCompleteTextView 选项消失
- rstudio - 有没有办法恢复被覆盖的旧版本的 .Rnw 文件?
- android - 如何在可组合的屏幕中使用协同程序?
- ios - 存档成功后看不到任何存档或组织
- javascript - 如何以与表单中的问题相同的顺序访问 Google 表单密钥对值
- javascript - 在 socket.io 的上下文中,响应 101 是什么意思?
- html - 如何创建一个带有环的圆形输入按钮?
- r - 将字符转换为逻辑