首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DiffableDataSource表视图标头中的问题

DiffableDataSource表视图标头中的问题
EN

Stack Overflow用户
提问于 2022-02-15 07:43:57
回答 1查看 117关注 0票数 1

我使用的是tableView,使用的是DiffableDataSource,也是我头上遇到的唯一问题。我使用viewForheaderSections方法调用标题标题视图,但在底部位置,而不是列表的顶部,请参阅代码,谢谢。

代码语言:javascript
复制
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)
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-15 08:08:34

根据您的代码,您没有使用viewForHeaderInSection。相反,您使用的是viewForFooterInSection。因此,在底部将出现一个footer,而不是一个footer

如果您只需要一个header,那么将与footer相关的所有方法更改为header

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71122703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档