首页 > 其他 > 详细

UITableView

时间:2015-07-12 21:31:11      阅读:200      评论:0      收藏:0      [点我收藏+]

一、表视图的结构

1、表视图由头部视图、尾部视图、中间一连串单元格组成

2、头部视图由tableHeaderView属性设置,尾部视图由tableFooterView属性设置

3、分组表格由一连串section视图组成,每个section又包含一个连续的单元格

4、每个section视图也有头部视图和尾部视图,通过委托方法设置

二、tabview的初始化

UITableView * tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth,kDeviceHeight) style:UITableViewStylePlain];

三、tabview的属性

_tableview=[[PullingRefreshTableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight-64) pullingDelegate:self];
_tableview.backgroundColor=[UIColor clearColor];
_tableview.delegate=self;
_tableview.dataSource=self;
_tableview.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
[mainScroll addSubview:_tableview];

四、tabview datasource必须实现的方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

  return [datasource count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

//根据标识去缓存池去取

static NSString *mycell=@"cell";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:mycell ];

//如果缓存池没有则重新创建并放到缓存池中
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mycell];
cell.selectionStyle=UITableViewCellSelectionStyleNone;

UIImageView * leftImg=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 60, 50)];
leftImg.backgroundColor=[UIColor clearColor];
leftImg.tag=20;

[cell.contentView addSubview:leftImg];

return cell;

}

 datasource 可选实现的方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

}

  //section中头部视图实现的标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

}

//指定单元格是否支持编辑

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

}

//指定单元格是否支持移动

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

}

//右侧添加一个索引表

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{

}

//响应点击索引时的委托方法
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{

}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

}

 

五、tabview delegate

//单元格的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 60;
}

//选中单元格的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

//设置头部、尾部视图的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; // custom view for header. 
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. 

UITableView

原文:http://www.cnblogs.com/momosmile/p/4641511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!