Xcode控件使用笔记四:UITableView

UITableView的两种内置样式:UITableViewStylePlain  和 UTTableViewStyleGrouped(分组)

1、分组例子 : storyboard选择一个UITableView,style设置为Grouped

//  ViewController.m
#pragma mark - 数据源方法
#pragma mark 一共有多少组数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
#pragma mark 第section组有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
#pragma mark 返回每一行显示的具体数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 组 indexPath.section
    // 行 indexPath.row
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    // 设置cell上面显示的文本数据
    cell.textLabel.text = city;
    
    return cell;
}
#pragma mark 第section组的标题 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
}
#pragma mark
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
}
#pragma mark 右侧快捷分组
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return self.provinces;
    //return @[@"A", @"B", @"C"];
}

2、单组例子 

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    
    // 图片的文件名
    NSString *name = [NSString stringWithFormat:@"00%d.png", indexPath.row + 1];
    
    // 设置左边的图标
    cell.imageView.image = [UIImage imageNamed:name];
    // 设置主标题
    cell.textLabel.text = @"123213213";
    // 设置副标题
    cell.detailTextLabel.text = @"详细描述------";
    
    // 设置cell的右边箭头样式 ->
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;

#pragma mark - 代理方法
#pragma mark 选中了某一行就会调用
- (void)tableView:(UITableView *)tableView didSelectRowA
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值