Set height to 0 to view UITableView title

I used the code below to set the height of the presentation of a UITableView header

- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = 0.0; //  

    return height;
}

but displayed abnormally as shown below

enter image description here

there is a white block, your comment is welcome

+5
source share
3 answers

You must return nilfrom your implementation- (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;
}
+5
source

The table frame is not set correctly. Check the code or nib

The delegate returns the height of the header, and it is correct in the table, because there is no space between the edge of the table and the cell

use the setFramemethod for proper installation through code

0 . , 0,

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

0 means the default value. Make the height very small, for example 0.01, to "hide" it.

+2
source

All Articles