views:

458

answers:

1

Imagine a table ("StyleGrouped") with multiple sections:

  • Some sections should have a "regular header title".
  • There should be some buttons, between the "regular sections".

Intuitively, in order to define the section titles, I would use:

(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

And in order to simulate the buttons, I would create custom UIViews via:

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

The problem is that by the time you start using viewForHeaderInSection, then titleForHeaderInSection stops working...

It makes sense somehow since we're now supposed to provide custom header views. The only problem is that there is no way to access the original UIView used by UIKit to render "regular header titles"...

Not the end of the world (i.e. creating your own UILabel and simulating the UIKit look & feel) but I'm just wondering if I missed something (?)

+2  A: 

It appears that viewForHeaderInSection gets called before titleForHeaderInSection. However if you do return nil for a specific row where you don't want to use a view, the titleForHeaderInSection is called.

Deepak
Thanks for the effort, but it's not fully solving the problem. Anyway it helped me discovering that the solution was to return an hard-coded value of 31 in (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section, whenever a "regular header title" has to be shown.
Ariel Malka
Correction: the original UIKIt height is 36. I personally still prefer 31 since it reduces the (oversized by default) top-margin...
Ariel Malka