ios - 如何使用现代 UICollectionViewDiffableDataSource 支持自定义单元格重新排序?
问题描述
基本上是标题。
如果您使用的是. UICollectionViewDiffableDataSource
,则无法使用 . 的传统方法对单元格重新排序collectionView.beginInteractiveMovementForItem(at: iPath)
。在 collectionView 上使用“InteractiveMovement”方法需要您实现collectionView(_:moveItemAt:to:)
哪个是UICollectionViewDataSource
协议方法,因为我没有使用,所以不能使用UICollectionViewDataSource
,我使用的是UICollectionViewDiffableDataSource
. 我尝试使用传统的“InteractiveMovement”方法使其工作,它们可能有 90% 的时间工作,但有时它们只是不起作用,我对此无能为力。
我设法收集到的唯一见解来自Apple 的“实现现代集合视图”,但这完全没用,因为演示代码显示如何支持重新排序的唯一方法是通过
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Emoji> { (cell, indexPath, emoji) in
var contentConfiguration = UIListContentConfiguration.valueCell()
contentConfiguration.text = emoji.text
contentConfiguration.secondaryText = String(describing: emoji.category)
cell.contentConfiguration = contentConfiguration
cell.accessories = [.disclosureIndicator(), .reorder(displayed: .always)]
}
具体来说,cell.accessories = [.disclosureIndicator(), .reorder(displayed: .always)]
它没用,因为我使用的是不支持添加魔法配件的自定义 collectionviewcell。
这里到底是什么解决方案?
解决方案
推荐阅读
- javascript - 不能将 window.innerWidth 与比较运算符一起使用
- publish-subscribe - Pub/Sub 忽略发布给自己
- c# - 代码片段快捷方式不适用于 Visual Studio 2019 和 Intellisense
- excel - Excel COM 对象未发布 (vb.net)
- python - python 交易机器人(纸面交易)
- java - Spring Data MongoDB Pagination 导致扫描对象/返回 > 1000
- avaloniaui - 更新订阅任务中的 UI
- python - Python 的数独检查器问题
- sql-server - 如何解决无法在函数中插入或删除的问题
- ruby-on-rails - 编辑产品和新产品表单提交轨道的无效签名错误