zoukankan      html  css  js  c++  java
  • 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 }
     
     
  • 相关阅读:
    第一个独立开发的游戏 怪斯特:零 已经上线APP STORE!
    Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
    java 实现 多态的 三要素
    mysql 基础语法掌握~ This is just the beginning.
    rem ~~ 你懂了吗?
    两个css之间的切换
    JavaScript高级程序设计(第3版)
    保持底部~~永远在底部
    文字要对齐!!!
    改变this不要怕!!!
  • 原文地址:https://www.cnblogs.com/Cheetah-yang/p/4664070.html
Copyright © 2011-2022 走看看