一 UITabelView 基础属性
1. 表视图 UITableView,iOS中重要的视图.
表视图通常用来管理一组具有相同数据结构的数据.
2. UITable 继承自UIScrollView, 所以可以滚动.
表视图的每一条数据都是显示在 UITableViewCell 对象中.
表视图的每一条数据都是显示在 UITableViewCell 对象中.
表视图可以分区显示数据,每个分区称为一个section,每一行称为 row, 编号都是从0开始.
3. UITableView 可以有多个分区(section)[相当于我们班中的分组],每个分区里 又有很多行(row)[相当于分分组里的组员]
二 表视图的创建及显示数据
1. 创建 UITableView 对象
UITableView*tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].boundsstyle:UITableViewStylePlain];
表视图的style有两种样式:UITableViewStylePlain
UITableViewStyleGrouped(主要用于分组)
2. 设置表的行高
tableView.rowHeight =80;
3. 设置表分割线颜色
tabelView.separatorColor= [UIColor brownColor];
4. 设置分割线的样式
tableViewseparatorStyle= UITableViewCellSeparatorStyleSingleLine;(有三种样式)
5. 设置分割线的边界(上,左,下,右)逆时针的方向
tableView.separatorInset= UIEdgeInsetsMake(0,0,0,0);
6. 表视图的表头(tableHeaderView)
定义一个 UIView 对象;表头视图很重要,一般会在这里放置轮播图
UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0,0,320,50)];
view.backgroundColor= [UIColor greenColor];
tableView.tableHeaderView = view; [view release];
7. 表视图的表尾(tableFooterView)
表头和表尾,当表里面没有内容的时候,只会显示表头视图和表尾视图.(紧挨在一起)
定义一个视图作为 cell 的下角
UIView *view =[[UIIView alloc]initWithFrame:CGRectMake(0,0,230,50)];
view.backgroundColor= [UIColor redColor];
tableView.tableFooterView= view;
[view release];
表视图如果没有内容,如何将那些没有内容的 Cell去除(快速去除的方法)
tableView.tableFooterView = [[[UIView alloc]init]autorelease];
8. 表视图的数据源属性(VVIP)配置数据源代理
1> 指定数据源的代理对象
tableView.delegate =self;
2> 遵循数据源代理的协议
在类中<UITableViewDataSource>
3> 实现数据源协议中的方法
① 配置tableView 每个分区对应的行数
-(NSInteger)tableView: (UITableView *)tableView numberOfRowsInSection
:(NSInteger)section;
② 用来创建每一行上的内容的方法(需要借助于 UITabelViewCell)
-(UITabelViewCell*)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath;
③ NSIndexPath 继承自 NSobject,用于存储 cell 所在的存储分区和在分区中的