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;
}
{
//
可重用标示符
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;
}
相关文章推荐
- 160_折半枚举(双向搜索) 4 Values whose sum is 0 (POJ No.2785)
- karma+requirejs
- poj1947Rebuilding Roads【树形dp】
- Purfer Sequence
- [easyui]封装一个dialog
- UIToolbar
- UINavigationBar
- UINavigationController
- 可删除超炫&多种特效的Card视图(改造自cardsui-for-android开源项目),提供DEMO下载
- UITextField 与键盘相关
- Interface Builder could not open the document "xxx.xib" because it does not exist.
- UIScroollView的使用和注意点
- 【原】Masonry+UIScrollView的使用注意事项
- Ubuntu 关闭guest用户
- UNIX(2) euid, suid, uid
- Android属性设置android:noHistory="true"
- WPF中使用UI线程
- jmeter java request
- powerbuilder调用dsoframer.ocx组件及操作 pb内嵌word组件及操作
- ui设计的思考