Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView heightForHeaderInSection not working

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?

like image 764
Jan Avatar asked Jun 26 '14 12:06

Jan


2 Answers

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;
like image 82
Jan Avatar answered Sep 29 '22 18:09

Jan


Swift:

Swift version of approved answer:

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNonzeroMagnitude
}
like image 39
nodehi Avatar answered Sep 29 '22 17:09

nodehi