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.
Related videos on Youtube
Author by
flopes
Updated on July 05, 2022Comments
-
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 over 12 yearsNo problem. If you could mark my answer as "Accepted" when you get the change I'd be most appreciative!
-
Ryan Booker over 12 yearsWhat if there is a header? Does returning a height of zero override the height of the header?
-
PEZ over 12 yearsRyan, in that case you should probably measure your header like you do with table cells and return that value.
-
SAHM over 12 yearsI 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 over 12 yearsI think the documentation is confusing in that it doesn't really explain how the
tableView:heightForHeaderInSection:
andtableView:viewForHeaderInSection:
work together. I think ios5 is saying that not implementingtableView: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.