194,重用UITableViewCell对象,提高性能

来源:互联网 发布:js cookie 过期时间 编辑:程序博客网 时间:2024/05/22 16:04

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

{

    // 可重用标示符

    static NSString *ID =@"Cell";

    

    // 让表格缓冲区查找可重用cell

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:ID];

    

    // 如果没有找到可重用cell

    if (cell == nil) {

        // 实例化cell

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ID];

    }

    

    // 设置cell内容

    // 1> 取出数据模型

    HMCarGroup *group = self.carGroups[indexPath.section];

    HMCar *car = group.cars[indexPath.row];

    

    // 2> 设置数据

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

    cell.textLabel.text = car.name;

    

    return cell;

}


0 0
原创粉丝点击