我按名称散列它们,所以当我更改金额时,它们应该在申请时顺畅地重新排序。当我在UICollectionViewDiffableDataSource上调用apply(snapshot, animatingDifferences: true)函数时,它不会使用平滑的动画对单元格进行重新排序,而是会闪烁,并且所有内容都已就位,没有“重新排序”。
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())发布于 2021-03-25 03:36:55
事实证明,UICollectionViewDiffableDataSource不仅使用散列来区分哪一项是哪一项,还使用==运算符。这就解决了这个问题:
struct Item: Hashable {
let name: String
let amount: Int
func hash(into hasher: inout Hasher) {
hasher.combine(name)
}
static func == (lhs: Category, rhs: Category) -> Bool {
return lhs.name == rhs.name
}
}https://stackoverflow.com/questions/66788151
复制相似问题