Вы можете добиться того же поведения, имея настраиваемую ячейку, которая будет действовать как заголовок в первых двух разделах. А затем удалите для них фактический заголовок.
Например:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0 || indexPath.section == 1) && indexPath.row == 0 {
return HeaderCell()
}
// return your desired cells (make sure to handle the number of
// rows properly as there is effectively 1 more than normal in
// in the first two sections now)
}
Вам также потребуется настроить заголовки для первых двух разделов:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 2 { return YourHeaderView() }
return nil
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 2 { return yourHeight }
return 0
}
Кроме того, в функции делегата numberOfRows
убедитесь, что вы добавили 1 (это будет HeaderCell
).