cell的重用

//当一个cell进入到视野范围内就会调用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
////    1.创建cell
//    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
//    NSLog(@"%ld ,%ld,%p",indexPath.section,indexPath.row,cell);
////    2.设置数据
//    HeroModel *hero = self.heros[indexPath.row];
////     2.1设置名称
//    cell.textLabel.text = hero.name;
////     2.2设置图片
//
//    cell.imageView.image = [UIImage imageNamed: hero.icon];
////     2.3设置子标题
//    cell.detailTextLabel.text = hero.intro;
////     2.4设置指示器
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//     return cell;
    
//    1.带着一个重用的标示符去缓存池中取重用cell
//     为了保证局部变量只开辟一次存储空间,我们用 static修饰局部变量
    static NSString *ID = @"hero";
   UITableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:ID];
//    2. 如果没有重用的cell,我们创建一个 cell
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        
    }
      NSLog(@"%ld ,%ld,%p",indexPath.section,indexPath.row,cell);
//    3.给cell设置数据覆盖原来的数据
    HeroModel *hero = self.heros[indexPath.row];
     //      3.1设置名称
     cell.textLabel.text = hero.name;
    ////     3.2设置图片
    //
     cell.imageView.image = [UIImage imageNamed: hero.icon];
    ////     3.3设置子标题
    cell.detailTextLabel.text = hero.intro;
    ////     3.4设置指示器
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
    
    
}

 

转载于:https://www.cnblogs.com/gp886/p/4941042.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值