我在 UITableView 中使用了新的 NSDiffableDataSourceSnapshot 和 UITableViewDiffableDataSource。我在构建表格时没有问题,但是当单元格中显示的数据发生变化时,我在更新单元格时遇到问题。我还没有找到任何解释如何执行此操作的 Apple 文档。我尝试了以下方法:
self.currentSnapshot.reloadItems([Item(identifier: identifier)])
self.dataSource.apply(self.currentSnapshot)
Run Code Online (Sandbox Code Playgroud)
我在 reloadItems 中收到以下错误:
断言失败 -[__UIDiffableDataSourceSnapshot _reloadViewUpdatesForDiffUpdate:dataSource:ignoreInvalidItems:]
我已经检查过传递给 Item 初始值设定项的标识符是否已经存在于快照中。
这是我的项目类:
class Item: Hashable, Equatable {
let identifier: String
var matchWrapper: MatchWrapper
init(matchWrapper: MatchWrapper) {
self.identifier = matchWrapper.identifier
self.matchWrapper = matchWrapper
}
func hash(into hasher: inout Hasher) {
hasher.combine(self.identifier)
}
static func == (lhs: ScoresViewController.Item, rhs: ScoresViewController.Item) -> Bool {
return lhs.identifier == rhs.identifier
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
uitableview ×1