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
}
Related videos on Youtube
Comments
-
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.
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.
What am I doing wrong?
-
ChintaN -Maddy- Ramani almost 10 yearsMake it Plain if you don't want group else you should add
heightForFooter
delegate andreturn 0
.
-
-
Jan almost 10 yearsReturning
0
inheightForFooterInSection
does not work. I tried also returningnil
inviewForFooterInSection
-
Pfitz almost 10 yearsseems like a bug. There are other answers to this problem with the same solution.
-
gnasher729 over 8 years@Jan: This seems to be both a hack and the solution :-(
-
bcause about 5 years2019 and still an issue. +1 for
sectionFooterHeight = 0
, this seems to be the cleanest solution. -
Jacob about 5 yearscombining this answer this with the post below, I use
tableView.sectionFooterHeight = CGFloat.leastNonzeroMagnitude
-
Viktor Malyi about 4 years2020 and still an issue
-
AZZ over 2 years2021 and still an issue. in iOS10.