cell内存优化
2024-08-30 10:10:04
UITableView的常用属性:
分割线颜色设置:
1》 设置separatorStyle: 分割线的颜色
方法:tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
2》 设置separatorColor 不用系统枚举的值,自己设定颜色的值
24bitRGB
R:8bit
G:8bit
B:8bit
===========
32bitRGBA
R:8bit
G:8bit
B:8bit
A:8bit 表示透明度alpha
# ff ff ff
设置值的时候用三原色的值比/255.0,这个结果是一个比值
方法:tableView.separatorColor = [[UIColor alloc] initWithRed:255/255.0 green:0/255.0 blue:0/255.0 alpha:255/255.0];
3》 tableView的其他属性 整个tableView的header和footer
tableView.tableFooterView = [[UISwitch alloc] init]; // 底部
tableView.tableHeaderView = [[UIProgressViewalloc] init]; // 头部
************************************************************************
cell:内存的优化
当我们用tableView得cell显示数据的时候,有时候数据量很大,如果不处理内存,我们向下或者向上滑动的时候
会不停的开辟存储空间;
处理代码:
1 // 每行显示的内容是什么
2 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
3 {
4
5 // 为我们创建的每个cell加标记
6 static NSString *identity = @"hero";
7 // 在创建cell时先从缓存迟中找被标记过的cell,当然这个缓存池是tableView创建的
8 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];
9
10 // 如果找不到,在创建带标记的cell
11 if (cell == nil) {
12 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];
13 }
14
15 // 然后再给每个cell设置数据
16 CXBheorsModel *models = self.heros[indexPath.row];
17 cell.textLabel.text = models.name;
18 cell.detailTextLabel.text = models.intro;
19 cell.imageView.image = [UIImage imageNamed:models.icon];
20
21 // 当每个cell移出界面时,tablView会自动把它放入缓存池
22 return cell;
23
24 }
最新文章
- 高性能的JavaScript--数据访问(1)
- Java排序算法——希尔排序
- 移动端web开发进阶
- [ubuntu] Can not run OpenProj on Ubuntu
- 【Toolkit】关闭Closeable的简单工具类
- asp.net同时调用JS和后台的无效的解决
- Linux Kernel系列一:开篇和Kernel启动概要
- ASP.NET Session丢失问题原因及解决方案
- Linux下使Shell 命令脱离终端在后台运行
- nodejs+express-实现文件上传下载管理的网站
- React-propsType和defaultProps
- 优化读取纯真IP数据库QQWry.dat获取地区信息
- CF235D Graph Game
- 650. 2 Keys Keyboard复制粘贴的次数
- angular2.0 官网架构文档
- Could not get lock /var/lib/dpkg/lock的解决方法
- c++11 delete禁用函数
- Putty全屏/退出全屏快捷键
- iOS:转载sqlite3
- 记录:Web无引用无配置方式动态调用WCF服务
热门文章
- Netty 仿QQ聊天室 (实战二)
- static 静态域 类域 静态方法 工厂方法 he use of the static keyword to create fields and methods that belong to the class, rather than to an instance of the class 非访问修饰符
- android打包签名,从生成keystore到完成签名
- Android笔记之强大的buildConfigField
- PAT 天梯赛 L3-010. 是否完全二叉搜索树 【Tree】
- Python 参数校验的进化
- 如何配置DSI时钟频率
- backbone测试代码
- hdu Integer Inquiry 解题报告
- php封装数据库mysql, mysqli