带标题部分的插入分组的UITableView

我已经将UITableView与两个原型单元格和插入分组样式一起使用

带标题部分的插入分组的UITableView

没有viewForHeaderInSection输出就可以了

带标题部分的插入分组的UITableView

添加viewForHeaderInSection后,输出将像这样

带标题部分的插入分组的UITableView

预期产量

带标题部分的插入分组的UITableView

这是我的代码

extension DashboardVC:UITableViewDelegate,UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 45
    }
    
    func tableView(_ tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat {
        return UITableView.automaticDimension
    }
    
    func tableView(_ tableView: UITableView,estimatedHeightForHeaderInSection section: Int) -> CGFloat {
        return 70
    }
    
    func tableView(_ tableView: UITableView,viewForHeaderInSection section: Int) -> UIView? {
        let headerCell = tableView.dequeueReusableCell(withIdentifier: "TblHeaderCell") as! TblHeaderCell
        return headerCell
    }
    
    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TblSectionCell",for: indexPath) as! TblSectionCell
        return cell
    }
}
iCMS 回答:带标题部分的插入分组的UITableView

首先,插入分组 tableView具有其他对齐属性...

如果您使用默认单元格并简单地设置if (querySnapshot?.documents.count)! > 0,则会看到节标题中的文本与单元格中的文本对齐。

此外,插入分组对行的部分的角进行了圆角处理-不包括该部分的标题。

使用普通的titleForHeaderInSection作为节标题视图的样子:

enter image description here

放大了一点:

enter image description here

要获得所需的视觉输出,我想您将要使用“标题单元格”作为该部分的第一行,而将“ section单元格”用于其余的行:

enter image description here

我猜您标题栏的“向下箭头/ V形”表示您要展开/折叠该栏目?如果是这样,则您需要重构代码以使该节折叠时仅显示第一行。

另一种选择是不使用插入分组,而是自定义单元格以使节标题的顶角和仅节中最后一个单元格的底角...或舍入该部分收合时标题的所有4个角。

本文链接:https://www.f2er.com/1802390.html

大家都在问