TTTableView自定义Section的例子 转自google论坛
2012-05-17 16:04
423 查看
IFor some weird Google bug I was not able to reply to the pertinent
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;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:
(NSInteger)section {
NSString* title = [[tableView.dataSource performSelector:@selector
(sections)] objectAtIndex:section];
if (title.length) {
return 30;
} else {
return 0;
}
}
@end
#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;
}
- (void)layoutSubviews {
_label.frame = CGRectMake(kDefaultMargin + kRoundedCellMargin, 0,
self.width, self.height);
}
@end
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;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:
(NSInteger)section {
NSString* title = [[tableView.dataSource performSelector:@selector
(sections)] objectAtIndex:section];
if (title.length) {
return 30;
} else {
return 0;
}
}
@end
#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;
}
- (void)layoutSubviews {
_label.frame = CGRectMake(kDefaultMargin + kRoundedCellMargin, 0,
self.width, self.height);
}
@end
相关文章推荐
- tableview自定义每个section的title
- 自定义tableView的section header/footerView时的view复用问题
- xcode 中tableView的section自定义…
- 绘制tableView 自定义section标头
- tableView自定义cell与api数据展示纪录(也是MVC的例子)
- iOS tableview viewForHeaderInSection 自定义
- three20里面的tttableview的自定义cell
- 让tableview的每个section的headerview随tableviewo一起滚动
- IOS xib在tableview上的简单应用(通过xib自定义cell)
- 去掉tableview中section的headerview粘性
- 改变tableview section headerView 的吸顶位置
- iOS学习之UITableView(三):进阶篇索引,标记和自定义的table
- UIColor用自定义颜色,TableView去掉背景色
- iOS开发笔记--多个Section的TableView
- **Android三五行代码结局有滑块,可滑动的TABLE导航栏。类似斗鱼直播的直播页面导航栏,滑块可动态根据栏目宽度适应,无需自定义view** 先来说下思路把,很简单,一个HorizontalS
- 设置tableView 的Section的title问题
- 自定义tableview分割线
- 【代码笔记】iOS-一个tableView,两个section
- 自定义UITableView的Section的title的样式
- iOS开发系列 ---- UI (自定义TableView)