2015年7月9日 UITableView

本文介绍如何为UITableView配置数据源,包括设置数据源、定义数据集的数量及每组数据的行数,以及如何显示每行信息等内容。同时,还介绍了如何添加表头和表尾,并提供了调整单元格高度的方法。

本文 是通过建模 获取数据的

UITableView  分为Grouped 模式  和  plain  模式

在写 UITableView 的时候需要先把 数据源 交给 控制器

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置数据源
    self.tableView.dataSource = self;
}

然后就是带哦用数据源方法

//有多少组数据

// How many sets of data
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.automobileGroups.count;
}

//每组数据有多少行

// section groups have how many rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    AutomobileGroups* a1 = self.automobileGroups[section];
    return a1.automobiles.count;
}

//每行的信息是什么
这里是这个如果 要添加  详情信息   就要换成这个 UITableViewCellStyleSubtitle

// Each row shows cell how
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    indexPath.row     行
//    indexPath.section   组
     AutomobileGroups* a1 = self.automobileGroups[indexPath.section];
   
    UITableViewCell* cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text =  a1.automobiles[indexPath.row];
 //cell.detailTextLabel.text    详情信息
    return cell;
    
}


// 如果 添加  头部  和  结尾 

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{//头部
    AutomobileGroups* ag = self.automobileGroups[section];
    return ag.title;
}

- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{//结尾
    AutomobileGroups* ag = self.automobileGroups[section];
    return ag.desc;
}

//修改table 的高度   默认 高度 为44

方法一

self.tableView.rowHeight = 60;

第二种 为代理的方法  

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //可以 改变  某些 行的行高
    return 60;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值