UITableView section header iOS 5

13,077

Per the release notes, your UITableViewDelegate MUST now return 0.0 from tableView:heightForHeaderInSection:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0;
}

Seems like a real pain. I don't know why they changed this, as everyone relies on the prior behavior - but they must have their reasons.

Share:
13,077

Related videos on Youtube

flopes
Author by

flopes

Updated on July 05, 2022

Comments

  • flopes
    flopes almost 2 years

    I have multiples tables delegated to a UIViewController. In IOS4 I used the function: (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section to change the background of some table header section. In those that do not have sections, I return nil and all works fine.

    In IOS5 if I return nil, the system puts one default header section. How do I hide the header section in the tables that I have only one section?

  • Steve
    Steve over 12 years
    No problem. If you could mark my answer as "Accepted" when you get the change I'd be most appreciative!
  • Ryan Booker
    Ryan Booker over 12 years
    What if there is a header? Does returning a height of zero override the height of the header?
  • PEZ
    PEZ over 12 years
    Ryan, in that case you should probably measure your header like you do with table cells and return that value.
  • SAHM
    SAHM over 12 years
    I think the header may be for aesthetic purposes. For example, I have a tabbed app, and one of the tabs didn't have section headers defined. When I switched to that tab, it always looked a bit off. So I will keep the empty header there for aesthetic purposes. I don't think it will be confusing to users.
  • Brynjar
    Brynjar over 12 years
    I think the documentation is confusing in that it doesn't really explain how the tableView:heightForHeaderInSection: and tableView:viewForHeaderInSection: work together. I think ios5 is saying that not implementing tableView:viewForHeaderInSection: and implementing it and returning nil both have the same meaning semantically - there is no custom view, so use the default one and turn if off if you want by setting the height to 0.