[ACCEPTED]-Default height for section header in UITableView-uitableview

Accepted answer
Score: 205

In IOS 5.0 onwards you can return UITableViewAutomaticDimension 2 in most of the delegate methods. Its at 1 the bottom of the documentation page

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == CUSTOM_SECTION)
    {
        return CUSTOM_VALUE;
    }
    return UITableViewAutomaticDimension;
}
Score: 51

From checking the defaults in my app it 5 looks like for a grouped table the default 4 is a height of 22 and for a non-grouped 3 table the default is a height of 10.

If you 2 check the value of the property sectionHeaderHeight 1 on your tableview that should tell you.

Score: 26

Actually do the trick :)

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
        return kFirstSectionHeaderHeight;
    return [self sectionHeaderHeight];
}

0

Score: 7

For the sake of completeness: in iOS7+ the 3 height for grouped style section headers 2 is 55.5 for the first and 38 for following headers. (measured 1 with DCIntrospect)

Score: 5

For swift 4.2 you should return UITableView.automaticDimension

0

Score: 2

I'm not sure what the correct answer is 5 here, but neither 10 or 22 appears to be 4 the correct height for a grouped table view 3 in iOS 5. I'm using 44, based on this question, and 2 it at least appears to roughly the correct 1 height.

Score: 2

To get the default height, just let super handle 1 it:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return kFirstHeaderHeight;

    return [super tableView:tableView heightForHeaderInSection:section];
}

More Related questions