我使用的是tableView,使用的是DiffableDataSource,也是我头上遇到的唯一问题。我使用viewForheaderSections方法调用标题标题视图,但在底部位置,而不是列表的顶部,请参阅代码,谢谢。
extension SinlgeTableViewcontroller:UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: Header.self)) as? Header else {return UIView()}
cell.lblHeader.text = "Top Mens"
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40
}
func createDataSource(){
dataSource = UITableViewDiffableDataSource<ProductsSections,AnyHashable>(tableView: tableView, cellProvider: { tableView, indexPath, itemIdentifier in
switch self.sectionsData[indexPath.section]{
case .first:
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProductCell.self)) as? ProductCell else {return UITableViewCell()}
cell.products = self.products[indexPath.row]
return cell
case .second:
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: MensCell.self)) as? MensCell else {return UITableViewCell()}
cell.mens = self.mens[indexPath.row]
return cell
}
})
}
func createSnapshot(){
var snapshot = NSDiffableDataSourceSnapshot<ProductsSections,AnyHashable>()
sectionsData.forEach{ $0
snapshot.appendSections([$0])
}
// snapshot.appendSections([.first,.second])
snapshot.appendItems(products, toSection: .first)
snapshot.appendItems(mens, toSection: .second)
dataSource?.apply(snapshot, animatingDifferences: true, completion: nil)
}发布于 2022-02-15 08:08:34
根据您的代码,您没有使用viewForHeaderInSection。相反,您使用的是viewForFooterInSection。因此,在底部将出现一个footer,而不是一个footer。
如果您只需要一个header,那么将与footer相关的所有方法更改为header。
https://stackoverflow.com/questions/71122703
复制相似问题