如何在3.section中添加标题?

问题描述

我有1.section的标头,但我想添加3.section。我该怎么办?

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

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
    }
    

这是屏幕截图,我想在屏幕截图上写上标题

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)