set height to 0 for header view of UITableView

swift 4

As other answers said, if you return 0 for height, it is means you say set default.

use small number like CGFloat.leastNonzeroMagnitude to solve problem.

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return CGFloat.leastNonzeroMagnitude
    }

hope this help.


The Tableview frame is not set properly.check in code or nib

The delegate return the headerview height and it is proper in the Table since there is no space between the edge of tableview and cell

use setFrame method to properly set via code

Setting height to 0 will not change section height of grouped table.So as a tweak use a very smaller value but not 0 like

- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = 0.001;   
    return height;
}