I have a UITableView where in some instances, certain sections have zero rows. My goal is that when this is true, I don't want any wasted space in the table view, it should look like there's no data.
The problem I'm having is with the header and footer for the sections, which are showing even if there's no row and despite me overriding the delegate method to return 0.0f.
Here's what it looks like - you can see the ~20p of gray space at the top there, headers and footers of about 10p each for a section with 0 rows.
(source: hanchorllc.com)
Here's my pseudo code:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if ([section hasRow]) {
return 10.0f;
} else {
return 0.0f;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if ([section hasRow]) {
return 10.0f;
} else {
return 0.0f;
}
}
I have verified that these methods are being called and that the proper execution path is taking place.
One wrinkle - this view controller is using a XIB and that UITableView has the section header and footer values set at 10.0 (default), though I thought that was overriden by the delegate method, if implemented.
This is an app targeting 3.0.
What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…