转载自:http://blog.sina.com.cn/s/blog_ac9efb7201015k2b.html
开始本教程之间首先简单的介绍一些Three20自身提供绘制列表的组件TTTableView,它继承与TableView将列表组件又封装了一次,封装了很多好看的列表样式。这部分内容比较简单并且官方已经封装至Three20项目包中的样例程序包中。Three20下载与安装配置环境,请阅读上一章博文。打开Three20文件夹,选择Samples->TTCatalog项目并且开打它,所有相关列表的样式都写在TableItemTestController类当中,如下图所示,大致的样式都在这里。
[cpp]
#import [td]
#import "TableViewDataSource.h"
@interface MovieController : TTTableViewController
{
}
@end
复制代码
[cpp]
#import "MovieController.h"
#import "MenuController.m"
#import "TableItem.h"
#import "TableItemCell.h"
#import "TableViewDataSource.h"
@implementation MovieController
- (void)viewDidLoad
{
}
- (void)createModel
{
}
- (void)didSelectObjectid)object atIndexPathNSIndexPath*)indexPath
{
}
@end
复制代码
列表资源类:
[cpp]
#import [td]
@interface TableViewDataSource : TTListDataSource
@end
复制代码
[cpp]
#import "TableViewDataSource.h"
#import "TableItem.h"
#import "TableItemCell.h"
@implementation TableViewDataSource
- (id)init {
}
- (Class)tableViewUITableView*)tableView cellClassForObjectid) object {
}
@end
复制代码
下面是列表的资源类TableItem。
[cpp]
#import [td]
@interface TableItem : TTTableLinkedItem {
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) UIImage *image;
@property (nonatomic, copy) UIColor *backcolor;
//初始化赋值
+ (id)itemWithTitleNSString *)title
@end
复制代码
[cpp]
#import "TableItem.h"
@implementation TableItem
@synthesize title = _title,image = _image, backcolor = _backcolor;
+ (id)itemWithTitleNSString *)title
}
- (id)init
{
}
- (void)dealloc
{
}
@end
复制代码
下面是列表的样式类TableItemCell。
[cpp]
#import [td]
@interface TableItemCell : TTTableLinkedItemCell {
}
@end
复制代码
tableView方法中设置列表中每个元素的高度。
initWithStyle方法中初始化列表中元素,这里创建一个文本框与图片视图并且加入整个窗口当中。
layoutSubviews方法中设置元素组件的显示区域,元素组建的坐标都是相对坐标,相对于每个列表元素的左上角点。
setObject这个方法比较重要,循环绘制列表之前会在这里获取在列表中显示的数据,参数为当前列表元素中的数据,在这里拿到屏幕中显示的文字与贴图还有背景颜色,并且全部设置入窗口视图当中。
这个方法用于设置按钮选中后的颜色,这里设置按钮选中后的颜色为蓝色,也可以在这里修改颜色。
self.selectionStyle = UITableViewCellSelection StyleBlue;
[cpp]
#import "TableItemCell.h"
#import "TableItem.h"
@implementation TableItemCell
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)item
{
}
- (id)initWithStyle:(UITableViewCellStyle)style
{
}
- (void)dealloc
{
}
- (void)layoutSubviews {
}
- (id)object
{
}
- (void)setObject:(id)object {
}
@end
复制代码
最后在重要的入口类中指定打开MovieController类。
[csharp]
#import "AppDelegate.h"
#import "MovieController.h"
@implementation AppDelegate
@synthesize window = _window;
- (void)dealloc
{
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp tions:(NSDictionary *)launchOptions
{
}
@end
复制代码
自定义列表中的元素已经映入我们眼帘,选中列表中某个元素后背景颜色为蓝色,点击后直接打开百度的网页。有了本章的知识,大家可以任意的使用Three20制作自定义列表啦。哇咔咔!!!!!
最后欢迎各位盆友可以在这一起讨论Three20软件开发,这两天学Three20学的实在是太爽了~~如果你觉得看得不清楚,下面是本章的源码,希望大家可以一起学习 哈哈~。哇咔咔~
(下载后必需搭建three20环境成功后才能运行~ 因为three20为引用加载,所以程序路径都是我本机的请见谅!或者你可可以将你的Three20路径修改的和我一样就可以直接运行啦,我的路径是:User (用户) -> Share(共享)->Three20)。