zoukankan      html  css  js  c++  java
  • IOS tableView的性能优化(缓存池)

    使用缓存池(标识类型)

    1.通过 一个 标识 去 缓存池 中寻找可循环得用的cell

    2.如果缓存池找不到可循环得用的cell:创建一个新的cell(给cell贴个标识)

    3.给cell设置新的数据

    本地数据性能优化(实例)

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        //static 修饰局部变量:可以保证局部变量只分配一次存储空间(只初化一次)
        static NSString *ID=@"hero";
        
        //1.通过一个标识去缓存池中寻找可循环利用的cell
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
        
        //2.如果没有可循环利用的cell(创建新的cell)
        if(cell==0)
        {
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
            NSLog(@"-----缓存池找不到cell--%d",indexPath.row);
        }
        //3.给cel设置新的数据
        //取出模型
         MJHero *hero=self.hero[indexPath.row];
                               
        //设置cell的数据
        cell.textLabel.text=hero.name;
        cell.detailTextLabel.text=hero.intro;
        cell.imageView.image=[UIImage imageNamed:hero.icon];
        
        //设置cell右边指示器的类型
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        
        return cell;
    }
  • 相关阅读:
    CF932E Team Work
    BZOJ 4480 [JSOI2013] 快乐的jyy
    CF285E Positions in Permutations
    P4312 [COCI 2009] OTOCI / 极地旅行社
    P3327 [SDOI2015]约数个数和
    P3649 [APIO2014]回文串
    P3181 [HAOI2016]找相同字符
    P3346 [ZJOI2015]诸神眷顾的幻想乡
    P4248 [AHOI2013]差异
    P4512 【模板】多项式除法
  • 原文地址:https://www.cnblogs.com/liuwj/p/6433643.html
Copyright © 2011-2022 走看看