IOS 学习 创建表格的方法

pragma mark - 数据源方法

/**
* 一共有多少组数据
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// NSLog(@”numberOfSectionsInTableView-一共有多少组数据”);
return 2;
}

/**
* 第section组有多少行
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// NSLog(@”numberOfRowsInSection-%d”, section);

if (section == 0) {
    return 3;
} else {
    return 4;
}

}

/**
* 每一行显示怎样的内容(cell)
*/
- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@”cellForRowAtIndexPath-%d组%d行”, indexPath.section, indexPath.row);
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

if (indexPath.section == 0) { // 德系品牌(第0组)

    if (indexPath.row == 0) { // 第0组的第0行
        cell.textLabel.text = @"奥迪";
    } else if (indexPath.row == 1) { // 第0组的第1行
        cell.textLabel.text = @"宝马";
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"奔驰";
    }

} else if (indexPath.section == 1) { // 日韩品牌(第1组)

    if (indexPath.row == 0) { // 第1组的第0行
        cell.textLabel.text = @"本田";
    } else if (indexPath.row == 1) { // 第1组的第1行
        cell.textLabel.text = @"丰田";
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"铃木";
    } else if (indexPath.row == 3) {
        cell.textLabel.text = @"三菱";
    }
}

return cell;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值