//当一个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;
}