I have a UITableView
with a filter button. If the button is pressed, it may happen, that the table is empty. To inform the user, I am adding a tableheader view in that case. If there are rows to show, I set the header back to nil.
Update: I am not talking about section header, I am talking about the table header.
Everything works as expected, but if the tableheader is removed, I see a gap over the table, that hasn't been there before. Any idea how to get rid if it?
This is the code:
if( _sections.count == 0 ) {
UIView *tableHeader = [self getTableHeader]; // make a view
self.tableView.tableHeaderView = tableHeader;
}
else {
self.tableView.tableHeaderView = nil;
[self.tableView reloadData]; // I added this as a test - no luck
}
This is how it looks before filtering everything away:
This is the "empty" case:
This is, if I remove the filter again:
have you tried setting the header height to 0.0f when section != 0 in: - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Edit:
I think the solution that you're looking for is replacing self.tableView.tableHeaderView = nil;
with: self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
found in Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7 by Mr. T