I used the code below to set the height of header view of UITableView
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
{
CGFloat height = 0.0; //
return height;
}
but it display abnormal, shown as below
there is a white block, your comment welcome
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;
}
You should return nil
from your implementation of - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//return header view for specified section of table view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//check header height is valid
if([self tableView:tableView heightForHeaderInSection:section] == 0.0)
{
//bail
return nil;
}
//create header view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, [self tableView:tableView heightForHeaderInSection:section])];
//
//return header view
return view;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With