如何将 header 添加到 3.section?

How do i add a header to 3.section?

我有 header 到 1.section 但我想添加 3.section。我该怎么做?

主屏幕有 3 个部分。我想添加 header 作为视图 这是我的 header 到第一个 header

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let view = UIView()
    view.sizeToFit()
    view.backgroundColor = .clear
    let titleLabel = UILabel(frame: CGRect(x: 0, y: 73, width: 250, height: 100))
    titleLabel.backgroundColor = .clear
    titleLabel.text = "Choose your \ntopics"
    titleLabel.textAlignment = .left
    titleLabel.numberOfLines = 0
    titleLabel.font = UIFont(name: "SFCompactDisplay-Semibold", size: 38)
    titleLabel.textColor = UIColor(red: 38/255, green: 50/255, blue: 91/255, alpha: 1)
    view.addSubview(titleLabel)
    return view   
}

这是tableView的属性

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        switch cells[section] {
        case .collection:
            return cells.count
        case .view:
            return 1
        case .list:
            return cells.count
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch cells[indexPath.row] {
        
        case .collection:
            let cell = tableView.dequeueReusableCell(withIdentifier: CollectionTableViewCell.identifier,
                                                     for: indexPath) as! CollectionTableViewCell
            cell.configure(with: models)
            return cell
            
        case .view:
            let cell = tableView.dequeueReusableCell(withIdentifier: FeaturedArticleTableViewCell.identifier,
                                                     for: indexPath) as! FeaturedArticleTableViewCell
            cell.configure(with: models[indexPath.row])
            return cell
            
        case .list:
            let cell = tableView.dequeueReusableCell(withIdentifier: ArticlesTableViewCell.identifier,
                                                     for: indexPath) as! ArticlesTableViewCell
            return cell
        }
        
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch cells[indexPath.row] {
        
        case .collection:
            return 67
            
        case .view:
            return 347
            
        case .list:
            return 130
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 194
    }
    

这是截图,我要header我在截图上写的地方

Return 基于 section 参数的不同视图:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    if section == 0 {
        let view = UIView()
        view.sizeToFit()
        view.backgroundColor = .clear
        let titleLabel = UILabel(frame: CGRect(x: 0, y: 73, width: 250, height: 100))
        titleLabel.backgroundColor = .clear
        titleLabel.text = "Choose your \ntopics"
        titleLabel.textAlignment = .left
        titleLabel.numberOfLines = 0
        titleLabel.font = UIFont(name: "SFCompactDisplay-Semibold", size: 38)
        titleLabel.textColor = UIColor(red: 38/255, green: 50/255, blue: 91/255, alpha: 1)
        view.addSubview(titleLabel)
        return view   
    }
    
    if section == 2 {
        let view = UIView()
        // configure your view for the 3rd section header
        return view
    }

}