我对UITableViewDiffableDataSource
进行了一些修改,并且能够毫无问题地加载tableView。我正在尝试在tableView中创建节标题,但是遇到了一些易燃的行为。
该部分枚举枚举定义如下:
enum AlertLevel: String, Codable, CaseIterable {
case green = "green"
case yellow = "yellow"
case orange = "orange"
case red = "red"
}
这是我对tableView(viewForHeaderInSection:)
的实现
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let label = UILabel()
label.text = dataSource.snapshot().sectionIdentifiers[section].rawValue.capitalized
label.textColor = UIColor.black
return label
}
这给了我4个标签,这些标签堆叠在tableView顶部的标题单元格中。
[我将Dash发射到RTFD,然后看到tableView(titleForHeaderInSection:)
是换皮那只猫的另一种方法。所以我把它扔进去了,]:>
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return dataSource.snapshot().sectionIdentifiers[section].rawValue.capitalized }
我在其中插入了一个断点,但它从未被击中。因此,我实现了
tableView(heightForHeaderInSection:)
,并且标头得到更新,但标头没有显示任何字符串。
该表加载LOT的速度比使用IndexPaths
的“老式方式”快(我正在使用USGS地震数据库学习TableViewDiffableDataSource
,但无法显示标题。
任何人都知道如何使部分在TableViewDiffableDataSource
上正常工作?我很难相信他们会在没有这种基本功能的情况下放任自流,所以我只能得出结论,我正在弄污某些东西……我不知道:)
哦...这就是我定义数据源的方式:
func makeDataSource() -> UITableViewDiffableDataSource<AlertLevel, Earthquake> {
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, earthquake in
let cell = tableView.dequeueReusableCell(withIdentifier: self.reuseID, for: indexPath)
cell.textLabel?.text = earthquake.properties.title
cell.detailTextLabel?.text = earthquake.properties.detail
return cell
}
}
我对UITableViewDiffableDataSource进行了一些修改,并且能够毫无问题地加载tableView。我正在尝试在tableView中创建节标题,但是我遇到了一些...
通过这样子类化UITableViewDiffableDataSource
类,我能够做到这一点: