cell内存优化

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 }
 
 

转载于:https://www.cnblogs.com/Cheetah-yang/p/4664070.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值