这篇笔记是介绍基于差量数据源(diffable data source)去更新列表展示的使用说明。对 UITableView 和 UICollectionView 都生效,这边笔记是用 UITableView 为例子的。
普通数据源方式
通常来说我们都是让包含 TableView 实例的视图控制器实现 UITableViewDataSource 协议,实现对应的方法,类似下面这样:
func numberOfSections(in tableView: UITableView) -> Int {
return data.sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.sections[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Identifier", for: indexPath)
//config cell
return cell
}
2/8/23About 6 min
