我有一个项目列表,它们在列表中按数量降序显示。我按名称对它们进行哈希处理,因此当我更改数量时,它们应该在应用时顺利重新排序。当我调用apply(snapshot, animatingDifferences: true)
函数 on 时UICollectionViewDiffableDataSource
,它不会以流畅的动画重新排序单元格,而是闪烁,并且一切都到位,没有“重新排序”。
struct Item: Hashable {
let name: String
let amount: Int
func hash(into hasher: inout Hasher) {
hasher.combine(name)
}
}
// when user taps, I call this
dataSource.apply(makeSnapshot())