PDA

View Full Version : UITableView grouped style custom section headers




North Bronson
Mar 6, 2009, 05:59 PM
When you use Apple's free header views for your sections (and add text for a title), does anyone know what is going on behind the scenes? Is it just a regular UILabel?

The reason that I ask is because I had to write some custom section headers with my own labels. I made the labels with a clear background so that the textured table background shows through. It seems like my table isn't scrolling quite as fast as it used to.

Is there any other way to show that textured background behind my label while keeping the label opaque? Is this what is going on when you use Apple's section views?



dejo
Mar 6, 2009, 06:51 PM
When you use Apple's free header views for your sections (and add text for a title), does anyone know what is going on behind the scenes? Is it just a regular UILabel?

The reason that I ask is because I had to write some custom section headers with my own labels. I made the labels with a clear background so that the textured table background shows through. It seems like my table isn't scrolling quite as fast as it used to.

Is there any other way to show that textured background behind my label while keeping the label opaque? Is this what is going on when you use Apple's section views?
The 'Cells and Table-View Performance' section of the "Table View Programming Guide for iPhone OS" recommends using opaque subviews or you may impact the performance of your table view. This is probably what is happening with your section headers.

Depending on the characteristics of your textured background, you may be able to include a similar background into your section titles and those avoid the need for transparency.

North Bronson
Mar 6, 2009, 06:56 PM
Depending on the characteristics of your textured background, you may be able to include a similar background into your section titles and those avoid the need for transparency.

All that I want is the same blue-and-white lines that you see behind the normal Apple grouped tableview.

dejo
Mar 6, 2009, 07:09 PM
All that I want is the same blue-and-white lines that you see behind the normal Apple grouped tableview.
If you are using a Grouped Style table view and are already getting the blue-and-white lines then, wow, I don't think there should be any impact in using the tableView:titleForHeaderInSection: since that just returns an NSString that I'm pretty sure gets converted into a UILabel for the section titles.

North Bronson
Mar 6, 2009, 07:18 PM
If you are using a Grouped Style table view and are already getting the blue-and-white lines then, wow, I don't think there should be any impact in using the tableView:titleForHeaderInSection: since that just returns an NSString that I'm pretty sure gets converted into a UILabel for the section titles.

Well, I kind of wanted to display the title in two different fonts and with different justifications. I don't think titleForHeaderInSection would give me that much control.

dejo
Mar 6, 2009, 08:16 PM
Well, I kind of wanted to display the title in two different fonts and with different justifications. I don't think titleForHeaderInSection would give me that much control.
It won't. But the trade-off for that control is a decrease in performance.

acl33
Apr 24, 2009, 05:41 AM
So how do I actually implement a custom section header? subclass UITableView and override the drawRect method, using [self rectForSection:<num>] to figure out where to render it?

Specifically, I'm wondering if I can add a UIButton to one of my section headers - so I want not just to draw a button, but also to respond to clicks on it. Any ideas, is this possible?

Cheers, Alan

Luke Redpath
Apr 24, 2009, 10:33 AM
You could always set the background to your custom header labels rather than having them clear:


mylabel.backgroundColor = [UIColor groupTableViewBackgroundColor];

North Bronson
Apr 25, 2009, 10:54 AM
You could always set the background to your custom header labels rather than having them clear:


mylabel.backgroundColor = [UIColor groupTableViewBackgroundColor];


Yes, that's what I ended up doing.