方法:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //创建cell

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    //设置cell的图片

    NSString *imageName = [NSString stringWithFormat:@"00%ld.png",indexPath.row + 1];

    cell.imageView.image = [UIImage imageNamed:imageName];

    //设置cell的主标题

    NSString * text = [NSString stringWithFormat:@"产品-%ld",indexPath.row + 1];

    cell.textLabel.text = text;

    //设置cell的附标题, 它的显示跟创建cell时的style有关

   // style = UITableViewCellStyleDefault :附标题不显示,图片显示

   // style = UITableViewCellStyleValue1 :附标题与祝标题平行显示,图片显示

   // style = UITableViewCellStyleValue2 :附标题显示,图片不显示

   // style = UITableViewCellStyleSubtitle :附标题与主标题上下显示,图片显示

    NSString *subtitle = [NSString stringWithFormat:@"产品-%ld很好",indexPath.row + 1];

    

    cell.detailTextLabel.text = subtitle;

    

    //设置右边的图标

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    

    return cell;

}

// 设置cell的高度继承delegate的方法:不仅要<UITableViewDataSource, UITableViewDelegate>,还要把控制器跟tableview的dataSource连线)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 70;

 }

相关文章:

  • 2021-11-14
  • 2021-04-10
  • 2021-11-12
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-30
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案