您的位置:首页 > 产品设计 > UI/UE

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

2016-01-10 16:06 323 查看
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

//
可重用标示符

static NSString *ID =
@"Cell";

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

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:ID];

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

if (cell == nil) {

//
实例化cell

cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:ID];

}

//
设置cell内容

// 1>
取出数据模型

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

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

// 2>
设置数据

cell.imageView.image = [UIImage
imageNamed:car.icon];

cell.textLabel.text = car.name;

return cell;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: