three20 自定义TTTableViewCell
来源:互联网 发布:qq牧场羽鹤数据 编辑:程序博客网 时间:2024/05/30 04:42
1 首先声明item,用于存储数据,需要提供一个对外创建借口,以及实现encode decode用于序列化
#import "Three20UI/TTTableTextItem.h"
@interface MyTableViewItem : TTTableTextItem{
NSString* _titleLabel;
NSString* _subTitleLabel;
}
+ (id)itemWithTitle:(NSString*)titleLabel SubTitle:(NSString*)subTitleLabel;
@property (copy, nonatomic)NSString* titleLabel;
@property (copy, nonatomic) NSString* subTitleLabel;
@end
#import "MyTableViewItem.h"
@implementation MyTableViewItem
@synthesize titleLabel = _titleLabel;
@synthesize subTitleLabel = _subTitleLabel;
- (void)dealloc{
[_titleLabel release];
_titleLabel = nil;
[_subTitleLabel release];
_subTitleLabel = nil;
[super dealloc];
}
+ (id)itemWithTitle:(NSString*)titleLabel SubTitle:(NSString*)subTitleLabel{
MyTableViewItem* myTableItem = [[[selfalloc]init]autorelease];
myTableItem.titleLabel = titleLabel;
myTableItem.subTitleLabel = subTitleLabel;
return myTableItem;
}
#pragma mark -
#pragma mark NSCoding
///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithCoder:(NSCoder*)decoder {
self = [superinitWithCoder:decoder];
if (self) {
self.titleLabel = [decoderdecodeObjectForKey:@"titleLabel"];
self.subTitleLabel = [decoderdecodeObjectForKey:@"subTitleLabel"];
}
return self;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)encodeWithCoder:(NSCoder*)encoder {
[super encodeWithCoder:encoder];
if (self.titleLabel) {
[encoder encodeObject:self.titleLabelforKey:@"titleLabel"];
}
if (self.subTitleLabel) {
[encoder encodeObject:self.subTitleLabelforKey:@"control"];
}
}
@end
2自定义Cell,实现initWithStyle方法,在首次调用新增控件时,创建控件,addsubview; 实现rowHeightForObject 和layoutSubviews@interface MyTableViewItemCell : TTTableViewCell{
UILabel* _title;
UILabel* _subTitle;
}
@property (nonatomic, retain) UILabel* title;
@property (nonatomic, retain) UILabel* subTitle;
@end
#import "MyTableViewItem.h"
#import "MyTableViewItemCell.h"
// Core
#import "Three20Core/TTCorePreprocessorMacros.h"
// Style
#import "Three20Style/TTGlobalStyle.h"
#import "Three20Style/TTDefaultStyleSheet.h"
#import "Three20UI/TTImageView.h"
#import "Three20UI/TTTableSubtitleItem.h"
#import "Three20UI/UIViewAdditions.h"
#import "Three20Style/UIFontAdditions.h"
#import "UITableViewAdditions.h"
@implementation MyTableViewItemCell
- (void)dealloc{
[_title release];
_title = nil;
[_subTitle release];
_subTitle = nil;
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {
self = [superinitWithStyle:UITableViewCellStyleValue2reuseIdentifier:identifier];
if (self) {
self.title.font =TTSTYLEVAR(tableFont);
self.title.textColor =TTSTYLEVAR(textColor);
self.title.highlightedTextColor =TTSTYLEVAR(highlightedTextColor);
self.title.backgroundColor =TTSTYLEVAR(backgroundTextColor);
self.title.adjustsFontSizeToFitWidth =YES;
self.subTitle.font =TTSTYLEVAR(font);
self.subTitle.textColor =TTSTYLEVAR(tableSubTextColor);
self.subTitle.highlightedTextColor =TTSTYLEVAR(highlightedTextColor);
self.subTitle.backgroundColor =TTSTYLEVAR(backgroundTextColor);
self.subTitle.textAlignment =UITextAlignmentLeft;
self.subTitle.contentMode =UIViewContentModeTop;
self.subTitle.lineBreakMode =UILineBreakModeWordWrap;
self.subTitle.numberOfLines =0;
}
return self;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTTableViewCell class public
///////////////////////////////////////////////////////////////////////////////////////////////////
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object {
MyTableViewItem* item = object;
CGFloat height = TTSTYLEVAR(tableFont).ttLineHeight +kTableCellVPadding*2;
if (item.titleLabel) {
height += TTSTYLEVAR(font).ttLineHeight;
}
if (item.subTitleLabel) {
height += TTSTYLEVAR(font).ttLineHeight;
}
return 80;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIView
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)prepareForReuse {
[superprepareForReuse];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)layoutSubviews {
[superlayoutSubviews];
CGFloat height = self.contentView.height;
CGFloat width = self.contentView.width - (height +kTableCellSmallMargin);
CGFloat left = 0.0f;
if (self.title.text.length) {
CGFloat textHeight =self.textLabel.font.ttLineHeight;
CGFloat subtitleHeight =self.detailTextLabel.font.ttLineHeight;
CGFloat paddingY = floor((height - (textHeight + subtitleHeight))/2);
self.title.frame =CGRectMake(left, paddingY, width, textHeight);
self.subTitle.frame =CGRectMake(left, self.textLabel.bottom, width, subtitleHeight);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTTableViewCell
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setObject:(id)object {
[super setObject:object];
MyTableViewItem* item = object;
if (item.titleLabel.length) {
self.title.text = item.titleLabel;
}
if (item.subTitleLabel.length) {
self.subTitle.text = item.subTitleLabel;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (UILabel*)title {
if (!_title) {
_title = [[UILabelalloc] init];
[self.contentViewaddSubview:_title];
}
return _title;
}
- (UILabel*)subTitle {
if (!_subTitle) {
_subTitle = [[UILabelalloc] init];
[self.contentViewaddSubview:_subTitle];
}
return_subTitle;
}
@end
3TTTableViewDataSource 中
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id)object添加
else if ([object isKindOfClass:[MyTableViewItem class]]) {
return [MyTableViewItemCellclass];
}
- three20 自定义TTTableViewCell
- Three20
- Three20
- Three20
- three20里面的tttableview的自定义cell
- Three20软件引擎之自定义TableView列表详解(二)
- Three20研究院之自定义TableView列表详解(二)
- Three20研究院之完全自定义TabBar(八)
- Three20软件引擎之自定义TableView列表详解
- [Three20] Three20的擴充模組
- [Three20] Three20介绍
- Three20 – Three20介绍
- [Three20] Three20的擴充模組
- [Three20] Three20系列之Three20概述
- three20介绍
- 使用Three20
- three20 network
- 关于three20
- CentOS mysql安装
- a 标签中调用js的几种方法(转)
- validation网址
- asp+access的网站实现随机调取文章
- 进程创建之copy_process函数
- three20 自定义TTTableViewCell
- 计划任务中使用NT AUTHORITY\SYSTEM用户和普通管理员用户有什么区别
- GTK+ 中的事件(events)和信号(signals)
- Axis2的相关准备工作,以及提供的一个简单的例子
- NoSQL数据库探讨之一 - 为什么要用非关系数据库?
- 汉字转拼音类
- RSA填充
- linux挂载与分配任务初识
- java实现排序算法(一)