tableView性能优化
来源:互联网 发布:网络销售彩票提成多少 编辑:程序博客网 时间:2024/06/05 06:28
tableView性能优化 - cell的循环利用方式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) if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; } // 3.覆盖数据 cell.textLabel.text = [NSString stringWithFormat:@"testdata - %zd", indexPath.row]; return cell;}
tableView性能优化 - cell的循环利用方式2
- 定义一个全局变量
// 定义重用标识NSString *ID = @"cell";
- 注册某个标识对应的cell类型
// 在这个方法中注册cell- (void)viewDidLoad { [super viewDidLoad]; // 注册某个标识对应的cell类型 [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];}
- 在数据源方法中返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // 1.去缓存池中查找cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 2.覆盖数据 cell.textLabel.text = [NSString stringWithFormat:@"testdata - %zd", indexPath.row]; return cell;}
tableView性能优化 - cell的循环利用方式3
在storyboard中设置UITableView的Dynamic Prototypes Cell
设置cell的重用标识
在代码中利用重用标识获取cell
// 0.重用标识// 被static修饰的局部变量:只会初始化一次,在整个程序运行过程中,只有一份内存static NSString *ID = @"cell";// 1.先根据cell的标识去缓存池中查找可循环利用的cellUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];// 2.覆盖数据cell.textLabel.text = [NSString stringWithFormat:@"cell - %zd", indexPath.row];return cell;
阅读全文
0 0
- TableView 性能优化
- TableView 性能优化
- tableView cell性能优化
- tableView性能优化
- TableView性能优化
- TableView性能优化
- tableView 性能优化机制
- iOS性能优化-TableView
- TableView性能优化
- tableView性能优化
- tableview性能优化
- tableView的性能优化
- tableView的性能优化
- tableView性能优化
- iOS tableView性能优化
- iOS TableView性能优化
- 优化 scrollView 性能(tableView)
- iOS TableView的性能优化
- CSS布局与定位——height百分比设置无效/背景色不显示
- 标准c++中string类函数介绍
- Tomcat配置详解
- JavaWeb三大组件之一Servlet【ServletContext(重要)】
- 由浅入深理解java集合(三)——集合-List
- tableView性能优化
- Python容器简介
- [leetcode]521. Longest Uncommon Subsequence I
- Github-Android Studio的配置
- 学会编写Android Studio插件 别停留在用的程度了
- navicat工具把SQL Server数据库转换MySQL数据库
- ulua热更新小试
- 随笔----音箱系统开发
- yield函数的学习及其应用