/**
* 标记多少行数据
*
* @param tableView tableView
* @param section 组号
*
* @return 返回行数
*/
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;// 两条
}
/**
* 每行如何显示
*
* @param tableView tableView
* @param indexPath
*
* @return 每行的内容
*/
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]init];
// initWithStyle:UITableViewCellStyleSubtitle 显示子标题
// UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
cell.textLabel.text = @"我是第一组";
cell.imageView.image = [UIImage imageNamed:@"m_10_100"];//添加图片
if(indexPath.section == 1)
{
cell.textLabel.text = @"我是第二组";
cell.imageView.image = [UIImage imageNamed:@"m_13_100"];
}
if(indexPath.section == 2)
{
cell.textLabel.text = @"我是第三组";
cell.imageView.image = [UIImage imageNamed:@"m_14_100"];
}
return cell;
}
-
分组的UITableView
- 把UITableView的style属性改为Grouped
- 实现
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView方法
/**
* 分组
*
* @param tableView tableView
*
* @return 返回几组
*/
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;// 两组
}
-
给UITableView添加头尾描述部分
- 实现
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section和-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section方法
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"我是头";
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return @"我是尾";
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。