arachide arachide - 1 year ago 98
iOS Question

set height to 0 for header view of UITableView

I used the code below to set the height of header view of UITableView

- (CGFloat)tableView:(UITableView *)tableView
CGFloat height = 0.0; //

return height;

but it display abnormal, shown as below

enter image description here

there is a white block, your comment welcome

Answer Source

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)
        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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download