Используйте tableView.numberOfSections
, чтобы получить счетчик секций .И используйте это значение в tableView(_:viewForHeaderInSection:)
, чтобы проверить, хотите ли вы вернуть SectionHeader
или nil
.Вам нужно вернуть nil
, если вы не хотите показывать header
в определенном section
.
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard tableView.numberOfSections > 1 else {
return nil
}
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! SectionHeader
//add rest of the code...
return headerView
}
Реализуйте tableView(_:heightForHeaderInSection:)
, чтобы вернуть header height
на основе section
.Верните 0
, если вы не хотите показывать header
в section
, иначе потребуется default header height
.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return (tableView.numberOfSections > 1) ? 100.0 : 0.0
}