views:

351

answers:

1

I have a UITableView that is styled as a grouped tableView. Under certain circumstances I need to create a custom view for the header and under other circumstances I want the default one.

Creating a custom header is the easy part - simply use the delegate:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

However, what do I return from this delegate if I want the default header view instead?

I've tried returning nil and this only works as expected when the table view is styled as Plain. If the table view is styled as Grouped then the default header disappears when I return nil.

How do I get the default header back taking into account that I need to sometimes have custom header views too?

Edit:

I think I've found the problem. In tableView:heightForHeaderInSection: I do the following:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if ([myArray count] == 0) return 80;
    else return [tableView sectionHeaderHeight];
}

It seems that [tableView sectionHeaderHeight] returns an incorrect height for my header. It sets it to 10 but it should be about 30.

A: 

Answered my own question in the edit. I needed to return a hard-coded height for the section header.

rein