iphone tableView的使用
2011-05-10 13:35
302 查看
tableView的使用主要处理代码
1.新建UIViewController页面,双击xib文件,打开布局视图
2.将Libery视图中的Table View拖到view窗口
3.单击view中的Tableview,control+F2,分别将dataSource和delegate和tableview fileowner关联
4.在页面中处理table数据显示
//测试数据
NSArray *listData;
NSArray *arry=[[NSArray alloc]
initWithObjects:@"列表item1",@"列表item2",@"列表item3",@"列表item4"
,nil
];
self.listData=arry;
[arry release];
/*
*
获得
lsitview
的
size
,就是
listview
的行数
*
Get ListView size;
*/
-(NSInteger)tableView:(UITableView
*)tableView
numberOfRowsInSection:(NSInteger)section{
return [self.listData count];
}
/********************
*
开始循环画
listview
*Draw Listview
*****************/
-(UITableViewCell
*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString
*SimpleTableIddentifier=@"SimpleTableIndentifier";//table
标志符
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIddentifier];
if(cell==nil){
cell=[[[UITableViewCell alloc]
initWithStyle:
UITableViewCellStyleDefault
//table
风格
reuseIdentifier:SimpleTableIddentifier
//table
标志符
] autorelease];
}
//
为每行添加一个
tupian
,建议图片资源预先处理好,直接调用,此处现取不建议
UIImage *image =[UIImage
imageNamed:@"green_dot.png"];
cell.imageView.image=image;
NSUInteger row=[indexPath row];
cell.textLabel.text=[
listData
objectAtIndex:row]; //此处导入数据源
UILabel* cellLabel = [cell textLabel];
[cellLabel setFont:[UIFont
fontWithName:@"Marker Felt" size:20]];
[cellLabel setTextColor:[UIColor whiteColor]];
[cellLabel setBackgroundColor:[UIColor
clearColor]];
return cell;
}
/*
处理
list
的选择事件
*
Deal select index
*/
-(NSIndexPath
*)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
NSInteger row =[indexPath row];
tab_myZone_AlterInfor *alterPage;//
修改账号信息页面定义
switch (row) {
case 0:
//
获取修改账号信息页面
alterPage=[[tab_myZone_AlterInfor
alloc] initWithNibName: @"tab_myZone_AlterInfor" bundle:nil];
self.alterInforPage=alterPage;
[alterPage release];
[self.navigationController pushViewController:self.alterInforPage
animated:YES ];
break;
default:
break;
}
return indexPath;
}
1.新建UIViewController页面,双击xib文件,打开布局视图
2.将Libery视图中的Table View拖到view窗口
3.单击view中的Tableview,control+F2,分别将dataSource和delegate和tableview fileowner关联
4.在页面中处理table数据显示
//测试数据
NSArray *listData;
NSArray *arry=[[NSArray alloc]
initWithObjects:@"列表item1",@"列表item2",@"列表item3",@"列表item4"
,nil
];
self.listData=arry;
[arry release];
/*
*
获得
lsitview
的
size
,就是
listview
的行数
*
Get ListView size;
*/
-(NSInteger)tableView:(UITableView
*)tableView
numberOfRowsInSection:(NSInteger)section{
return [self.listData count];
}
/********************
*
开始循环画
listview
*Draw Listview
*****************/
-(UITableViewCell
*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString
*SimpleTableIddentifier=@"SimpleTableIndentifier";//table
标志符
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIddentifier];
if(cell==nil){
cell=[[[UITableViewCell alloc]
initWithStyle:
UITableViewCellStyleDefault
//table
风格
reuseIdentifier:SimpleTableIddentifier
//table
标志符
] autorelease];
}
//
为每行添加一个
tupian
,建议图片资源预先处理好,直接调用,此处现取不建议
UIImage *image =[UIImage
imageNamed:@"green_dot.png"];
cell.imageView.image=image;
NSUInteger row=[indexPath row];
cell.textLabel.text=[
listData
objectAtIndex:row]; //此处导入数据源
UILabel* cellLabel = [cell textLabel];
[cellLabel setFont:[UIFont
fontWithName:@"Marker Felt" size:20]];
[cellLabel setTextColor:[UIColor whiteColor]];
[cellLabel setBackgroundColor:[UIColor
clearColor]];
return cell;
}
/*
处理
list
的选择事件
*
Deal select index
*/
-(NSIndexPath
*)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
NSInteger row =[indexPath row];
tab_myZone_AlterInfor *alterPage;//
修改账号信息页面定义
switch (row) {
case 0:
//
获取修改账号信息页面
alterPage=[[tab_myZone_AlterInfor
alloc] initWithNibName: @"tab_myZone_AlterInfor" bundle:nil];
self.alterInforPage=alterPage;
[alterPage release];
[self.navigationController pushViewController:self.alterInforPage
animated:YES ];
break;
default:
break;
}
return indexPath;
}
相关文章推荐
- iphone tableView的使用(zz)
- iphone tableView的使用(zz)
- iOS 使用tableview 代码布局时,tableViewCell宽度问题,运行在iPhone 6plus 仍然显示320
- Swift中tableView的建立与使用
- 【iOS7开发笔记】tableview之使用xib封装一个view的步骤
- 上拉刷新 EGORefreshTableHeaderView的使用窍门
- tableHeaderView与tableFooterView的使用
- 使用TableView
- Xcode8 TableView使用静态表单页面显示空白的问题
- TableViewController 使用,TableView 一些常用的方法
- iOS学习--列表下拉/上拉刷新: (一)EGORefreshTableHeaderView使用、定义EGORefreshTableFooterView
- TableView的基本使用
- 使用TableView时,头部空出20像素的解决办法
- iPhone开发之UIScrollView滚动组件的使用(一) 拖线实现——大图的移动展示
- 【iOS开发-58】tableView初识:5个重要方法的使用和2种样式的差别
- Q6:关于xcode TableView使用Nib文件出现Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:错误
- cocos2dx3.0 超级马里奥开发笔记(一)——loadingbar、TableView和pageview的使用
- tableview使用xib 创建cell
- iOS开发-UI控件:使用TableView实现多级树型menu
- 关于COCOS2DX里面TableView控件使用的问题