我正在使用使用 DiffableDataSource 的 tableView 并且只有我在標題中遇到的問題。我正在使用 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)
}
uj5u.com熱心網友回復:
根據您的代碼,您沒有使用viewForHeaderInSection. 而不是你正在使用的viewForFooterInSection. 所以不是 a header, afooter將出現在底部。
如果您只需要header更改所有footer與header.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427922.html
