UITableView heightForHeaderInSection not working

13,377

Solution 1

What seems to work is this

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001f; // 0.0f does not work
}

or even better, in loadView

self.tableView.sectionFooterHeight = 0.0f;

Solution 2

Swift:

Swift version of approved answer:

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNonzeroMagnitude
}
Share:
13,377

Related videos on Youtube

Jan
Author by

Jan

Doing iOS @ N26, previously @ HERE, Fyber and 360dialog

Updated on June 26, 2022

Comments

  • Jan
    Jan almost 2 years

    I have a simple UITableView (sample project here) but the section headers do not respect the height I'm setting in the heightForHeaderInSection

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 40;
    } 
    

    The table view looks like this. The 1 section header has a correct height but not the other ones.

    enter image description here

    When I inspect the view with the Reveal app, it seems that there is a kind of footer after the last cell in the section.

    enter image description here

    What am I doing wrong?

    • ChintaN -Maddy- Ramani
      ChintaN -Maddy- Ramani almost 10 years
      Make it Plain if you don't want group else you should add heightForFooter delegate and return 0.
  • Jan
    Jan almost 10 years
    Returning 0 in heightForFooterInSection does not work. I tried also returning nil in viewForFooterInSection
  • Pfitz
    Pfitz almost 10 years
    seems like a bug. There are other answers to this problem with the same solution.
  • gnasher729
    gnasher729 over 8 years
    @Jan: This seems to be both a hack and the solution :-(
  • bcause
    bcause about 5 years
    2019 and still an issue. +1 for sectionFooterHeight = 0, this seems to be the cleanest solution.
  • Jacob
    Jacob about 5 years
    combining this answer this with the post below, I use tableView.sectionFooterHeight = CGFloat.leastNonzeroMagnitude
  • Viktor Malyi
    Viktor Malyi about 4 years
    2020 and still an issue
  • AZZ
    AZZ over 2 years
    2021 and still an issue. in iOS10.

Related