thread, so I though I would just start a new one with this working
code. I am still not convinced this is the best way to do this, but
it works.
#import "Three20/TTTableViewDelegate.h"
#import "Three20/TTTableHeaderView.h"
@implementation TTTableViewDelegate (SectionTitlesCategory)
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:
(NSInteger)section {
if (tableView.style == UITableViewStylePlain && TTSTYLEVAR
(tableHeaderTintColor)) {
if ([tableView.dataSource respondsToSelector:@selector
(tableView:titleForHeaderInSection:)]) {
NSString* title = [tableView.dataSource tableView:tableView
titleForHeaderInSection:section];
if (title.length) {
TTTableHeaderView* header = [_headers objectForKey:title];
if (!header) {
if (!_headers) {
_headers = [[NSMutableDictionary alloc] init];
}
header = [[[TTTableHeaderView alloc] initWithTitle:title]
autorelease];
[_headers setObject:header forKey:title];
}
return header;
}
}
} else if (tableView.style == UITableViewStyleGrouped) {
if ([tableView.dataSource respondsToSelector:@selector(sections)]) {
NSString* title = [[tableView.dataSource performSelector:@selector
(sections)] objectAtIndex:section];
if (title.length) {
TTTableHeaderView *header = [_headers objectForKey:title];
if (!header) {
if (!_headers) {
_headers = [[NSMutableDictionary alloc] init];
}
header = [[[TTTableHeaderView alloc] initWithTitle:title]
autorelease];
[header
setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[_headers setObject:header forKey:title];
}
return header;
}
}
}
return nil;
(NSInteger)section {
NSString* title = [[tableView.dataSource performSelector:@selector
(sections)] objectAtIndex:section];
if (title.length) {
return 30;
} else {
return 0;
}
#import "Three20/TTTableHeaderView.h"
@implementation TTTableHeaderView (SectionTitlesCategory)
- (id)initWithTitle:(NSString*)title {
if (self = [super init]) {
self.backgroundColor = [UIColor clearColor];
self.style = TTSTYLE(groupedTableSectionHeader);
_label = [[UILabel alloc] init];
_label.text = title;
_label.backgroundColor = [UIColor clearColor];
_label.textColor = TTSTYLEVAR(tableHeaderTextColor) ? TTSTYLEVAR
(tableHeaderTextColor) : TTSTYLEVAR(linkTextColor);
_label.shadowColor = TTSTYLEVAR(tableHeaderShadowColor) ? TTSTYLEVAR
(tableHeaderShadowColor) : [UIColor clearColor];
_label.shadowOffset = CGSizeMake(0, 1);
_label.font = FONT_GROUPED_SECTION_HEADER_FONT;
[self addSubview:_label];
}
return self;
_label.frame = CGRectMake(kDefaultMargin + kRoundedCellMargin, 0,
self.width, self.height);