<二>UITableViewCell的重用(性能优化)

来源:互联网 发布:java分布式开发详解 编辑:程序博客网 时间:2024/06/05 03:39

/**

 *  cellForRowAtIndexPath函数 每当有一个cell进入视野范围内,就会调用

 *  

 */


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

{

// 创建cell标识

staticNSString * ID =@"heroCell";

// cell缓存池中取出 对应ID标识 可重用cell

UITableViewCell * cell = [tableViewdequeueReusableCellWithIdentifier:ID];

// 缓存池中没有可重用cell 就重新创建

if (cell ==nil) {

cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];

}


//取模型数据

Heros *hero =self.hero[indexPath.row];

// 相关cell赋值操作

cell.textLabel.text = hero.name;

cell.detailTextLabel.text = hero.intro;

cell.imageView.image = [UIImageimageNamed:hero.icon];

cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;


return cell;

}


0 0
原创粉丝点击