Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mix "Custom Section Header View(s)" and "Regular Header(s)" in a UITableViewController?

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 (?)

like image 476
Ariel Malka Avatar asked Feb 03 '10 22:02

Ariel Malka


1 Answers

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.

like image 180
Deepak Danduprolu Avatar answered Nov 07 '22 09:11

Deepak Danduprolu