UITableView
2015-07-12 20:55
232 查看
一、表视图的结构
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.
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.
相关文章推荐
- 提高Interface Builder高效工作的8个技巧
- iOS 9: UIStackView入门
- Keil V5.1x命令“Build Target”重新编译所有文件
- Android核心分析之GUI框架的原理
- 详解 UIView 的 Tint Color 属性
- 前端开发工具vue.js开发实践总结
- Java_GUI中GridBagLayout布局使用详解
- Java中GUI界面美化帮助类总结
- iOS --- 去掉UITableView中的空白行
- [LeetCode] Implement Stack using Queues
- 关于querySelector()与querySelectorAll()的在ie下的一点与众不同之处。
- 使用Git、Git GUI和TortoiseGit
- OpenGL蓝宝书第五章5.4Tunnuel 纹理映射和过滤:较好的可读性代码
- 1626 - Brackets sequence(DP)
- 4.Median of Two Sorted Arrays(Array; Divide-and-Conquer)
- POJ 2784 Buy or Build最小生成树
- Failed to convert property value of type 'com.sun.proxy.$Proxy8 implementing
- EasyUI DataGrid和Pagination
- mongoVue的使用
- break与continue的区别