0

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:

everything crisp and clean, no gap.

This is the "empty" case:

all data filtered: Show the message

This is, if I remove the filter again:

removed filter again

thst
  • 4,592
  • 1
  • 26
  • 40

1 Answers1

1

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

Community
  • 1
  • 1
aduflo
  • 81
  • 4
  • You suggest, that the gap is actually the first section? Because I have not changed the section-header code, I added a table header ... – thst Jan 19 '16 at 23:48
  • I'm not fully sure - but when adding section headers I generally make sure to handle the height for all cases. I might be misunderstanding though, is this a header for the tableview or a header for the section? – aduflo Jan 19 '16 at 23:57
  • It is not the section header, it is the tableheader. – thst Jan 20 '16 at 00:25
  • 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 http://stackoverflow.com/questions/18880341/why-is-there-extra-padding-at-the-top-of-my-uitableview-with-style-uitableviewst by Mr. T – aduflo Jan 20 '16 at 00:42
  • Please edit your answer to reflect the solution from the comment. The answer above is not correct, the comment did the trick. Thanks! – thst Jan 20 '16 at 00:46