代码改变世界

UITableVIewCell的设置(附标题/高度/右边的标识)

2015-07-13 11:19  一树一菩提  阅读(764)  评论(0编辑  收藏  举报

方法:

-(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;

 }