我已经将UITableView
与两个原型单元格和插入分组样式一起使用
没有viewForHeaderInSection
输出就可以了
添加viewForHeaderInSection
后,输出将像这样
预期产量
这是我的代码
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
}
}