ios tableView性能优化策略
来源:互联网 发布:买家淘宝购物流程 编辑:程序博客网 时间:2024/06/10 18:40
性能优化方法1:
/**
* 什么时候调用:每当有一个cell进入视野范围内就会调用*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 0.重用标识
// 被static修饰的局部变量:只会初始化一次,在整个程序运行过程中,只有一份内存
static NSString *ID = @"cell";
// 1.先根据cell的标识去缓存池中查找可循环利用的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 2.如果cell为nil(缓存池找不到对应的cell),创建一个cell 并标志
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
// 3.覆盖数据
cell.textLabel.text = [NSString stringWithFormat:@"testdata - %zd", indexPath.row];
return cell;
}
性能优化方法2:
static NSString *ID = @"cell";
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.去缓存池中查找cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 2.覆盖数据
XMGHero *hero = self.heroes[indexPath.row];
cell.textLabel.text = hero.name;
cell.imageView.image = [UIImage imageNamed:hero.icon];
cell.detailTextLabel.text = hero.intro;
return cell;
}
0 0
- ios tableView性能优化策略
- iOS性能优化-TableView
- iOS tableView性能优化
- iOS TableView性能优化
- iOS TableView的性能优化
- ios TableView性能优化技巧
- iOS性能优化策略
- iOS性能优化策略
- TableView在iOS上的性能优化
- TableView在iOS上的性能优化
- IOS常用的性能优化策略
- TableView 性能优化
- TableView 性能优化
- tableView cell性能优化
- tableView性能优化
- TableView性能优化
- TableView性能优化
- tableView 性能优化机制
- css sprite的实现
- 正确增加Cloneable接口
- uva10820(简单数学题)
- partition-list
- apache2.4 以上的版本,cgi-bin中的文件不能运行。
- ios tableView性能优化策略
- 我也开博客了……
- 非你莫属 周倩如 女程序员 神一样的选手!
- maven编译代码详细介绍
- 抢测试1
- TopCoder SRM 661 Div2 Problem 500 - BridgeBuildingDiv2 (枚举 + 状态压缩)
- Doubles
- 如何在header头前输出变量,如何在sesion_start前echo,如何存取phpinfo()的内容?
- 管道有名管道