cell的循环利用

来源:互联网 发布:ipad 看图软件 编辑:程序博客网 时间:2024/05/17 23:57

这里写图片描述
// 离开屏幕的cell会怎样

/**
* 每当有一个cell进入视野范围内,就会调用
*/
- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// static修饰局部变量:可以保证局部变量只分配一次存储空间(只初始化一次)
static NSString *ID = @”hero”;

// 1.通过一个标识去缓存池中寻找可循环利用的cell// dequeue : 出列 (查找)UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 2.如果没有可循环利用的cellif (cell == nil){    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

// NSLog(@”——缓存池找不到cell–%d”, indexPath.row);
}

// 3.给cell设置新的数据// 取出模型MJHero *hero = self.heros[indexPath.row];// 设置cell的数据cell.textLabel.text = hero.name;cell.detailTextLabel.text = hero.intro;cell.imageView.image = [UIImage imageNamed:hero.icon];return cell;

}

0 0
原创粉丝点击