• UITableView的常用属性和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的其他属性 整个tableViewheaderfooter

        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 }

     

  • 相关阅读:
    等宽布局和flex
    antd按需加载
    linux-redis cluster集群(redis5.x)
    linux-mysql-主从同步
    mysql-行转列
    Spring Bean 作用域
    ArrayList、LinkedList区别(jdk8)
    java类及实例初始化顺序
    线程池-结构
    GIT基础
  • 原文地址:https://www.cnblogs.com/cxbblog/p/3765032.html
Copyright © 2020-2023  润新知