UITableView cell的重复使用
来源:互联网 发布:上海进出口数据 编辑:程序博客网 时间:2024/04/29 22:04
概述
当tableView 中的cell有很多时,可能会造成内存不够的情况。iOS中有cell缓存池,每个cell有个标志,不同是为了区别不同cell。
当一个屏幕只能显示4个cell时,只需要创建多一个cell在缓存池中,就可以满足满足上下滑时,cell的循环使用。
重用原理
重用原理:当滚动列表时,部分UITableViewCell会移出窗口,UITableView会将窗口外的UITableViewCell放入一个对象池中,等待重用。当UITableView要求dataSource返回UITableViewCell时,dataSource会先查看这个对象池,如果池中有未使用的UITableViewCell,dataSource会用新的数据配置这个UITableViewCell,然后返回给UITableView,重新显示到窗口中,从而避免创建新对象。
循环使用实现
/** * 每当有一个cell进入视野范围内,就会调用 */- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //定义cell的标志。static修饰局部变量:可以保证局部变量只分配一次存储空间(只初始化一次) static NSString *ID = @"hero"; //1.通过一个标志去缓存池中寻找可以循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; //2.如果没有可以循环利用的cell,从缓存池中取出cell if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } //3.给cell设置新的数据 QTHero *hero = self.heros[indexPath.row]; //4.设置cell的属性 cell.textLabel.text = hero.name; cell.detailTextLabel.text = hero.intro; cell.imageView.image = [UIImage imageNamed:hero.icon]; return cell;}
0 0
- UITableView cell的重复使用
- UITableView的Cell排序
- UITableView cell的重用
- UITableView 的 自定义cell
- UITableView的自定义cell
- 改变UITableView Cell的字体
- UITableView 删除特定的CELL
- 关于UITableView的Cell复用
- 禁止编辑UITableView的Cell
- UITableView获取cell的indexPath
- UITableView cell 的动态使用
- 关于UITableView的Cell复用
- UITableView Cell的属性方法
- UITableView 的cell重叠问题
- IOS UITableview 的Cell 封装
- UITableView 删除cell 的问题
- UITableView出现多余的cell
- UITableView的cell自适应高度
- HTML
- window7快捷键
- 区域传输技术
- Java 语言基础
- Python ImportError: cannot import name *
- UITableView cell的重复使用
- [Android教学区] 138. singleTask和singleInstance启动模式
- 在eclipse中输入.后没有提示
- sql No Dialect mapping for JDBC type: -9 解决方案
- ubuntu出现循环登录的问题
- 第十三篇:ARC自动引用计数器原理
- [leetcode] 139 Word Break
- UNIX STDOUT_FILENO验证
- 自定义JTabbedPane的标签栏