1.表视图继承于UIScrollView 是可以滚动的
2.表示图的每一条数据都是显示在UITableViewCell对象中
3.表示图可以分区显示数据,每个分区称为一个section ,每一行称为row 编号都是从0 开始
4.重要的属性 style样式 : plain,group 分割线 separatorStyle 分割线的颜色 separatorColor 行高 rowHeight
UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height-64)style:UITableViewStylePlain];
tableview.rowHeight=44;//UITableView 的高度
tableview.separatorColor = [UIColor redColor];//设置分割线的颜色
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 30, 60, 60)];
[view setBackgroundColor:[UIColor cyanColor]];//背景颜色
[self.view addSubview:view];
[view release];
tableview.tableHeaderView=view;
nav.navigationBar.barTintColor = [UIColor greenColor];//导航栏文字的颜色
5.//设置头标题的高度
//设置脚标题的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 30;<pre name="code" class="objc">//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
if (indexPath.row == 0) {
return 40;
}
else if (indexPath.row == 1){
return 80;
}
else if (indexPath.row == 2){
return 100;
}
}
return 40;
}
<pre name="code" class="objc" style="color: rgb(0, 143, 0); font-size: 18px;">6.<span style="font-family: 'Heiti SC Light';">//设置头标题的名称</span>
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;{ if (section == 0) { return @"A"; } return @"B"; return @"通讯录";}
}7.//右侧添加一个索引表- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ NSMutableArray *arr = [NSMutableArray array]; for (int i = 65; i <= 90; i++) { [arr addObject:[NSString stringWithFormat:@"%c", i]]; } return arr;}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
8.返回五个section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;//五个section
}
//第一种:当前视图添加到父视图的时候(布局他的子视图)
//第二种 : 当前视图改变坐标时,
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.imagesView1 = [[UIImageView alloc]initWithFrame:CGRectZero];
[_imagesView1 setBackgroundColor:[UIColor redColor]];
[self.contentView addSubview:_imagesView1];
[_imagesView1 release];
self.titleLable = [[UILabel alloc]initWithFrame:CGRectZero];
[self.contentView addSubview:_titleLable];
[_titleLable release];
self.timeLable = [[UILabel alloc]initWithFrame:CGRectZero];
[self.contentView addSubview:_timeLable];
[_timeLable release];
self.datailLable = [[UILabel alloc]initWithFrame:CGRectZero];
[self.contentView addSubview:_datailLable];
[_datailLable release];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
[self.imagesView1 setFrame:CGRectMake(10, 5, 60, 60)];
[self.titleLable setFrame:CGRectMake(80, 5, 100, 30)];
[self.timeLable setFrame:CGRectMake(250, 40, 100, 20)];
[self.datailLable setFrame:CGRectMake(80, 45, 30, 30)];
}