zoukankan      html  css  js  c++  java
  • UITableVIew的性能优化-重用原理

    UITableVIew的性能优化:使用方法创建cell时,先优先从缓存池中找cell,找不到再创建新的cell,并且要绑定Identifer标示。

    代码:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //    定义一个静态的标识(只会初始化一次,内存分配一次)

        static NSString *ID = @"c1";

    //    优先从缓存池中去找cell

        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];

    //    缓存池中找不到就创建一个新的cell,一定要绑定标示

        if (cell == nil) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

        }

  • 相关阅读:
    格式与布局
    iframe
    tp
    头信息
    php 文件下载
    socket
    Flex 布局2
    Flex 布局
    下拉刷新
    选取一种类中含有某一属性值得元素的集合
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4646789.html
Copyright © 2011-2022 走看看