Ariel Malka
Ariel Malka

Reputation: 15987

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

Imagine a table ("StyleGrouped") with multiple 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 (?)

Upvotes: 10

Views: 3596

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

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.

Upvotes: 9

Related Questions