zoukankan      html  css  js  c++  java
  • Tableview 优化Cell的复用机制01

    #import "ViewController.h"
    
    @interface ViewController ()<UITableViewDataSource>
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        UITableView *tab=[[UITableView alloc]init];
        tab.frame=self.view.bounds;
        tab.dataSource=self;
        tab.rowHeight=70;//行高
        [self.view addSubview:tab];
    }
    #pragma mark-<UITableViewDataSource>数据源
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 100;
    }
    //每当有cell进入屏幕中就会调用
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //    UITableViewCell *cellaaa=[[UITableViewCell alloc]init];
    ////    cellaaa.textLabel.text=@"666";
    ////    %d->int
    ////    %zd->NSInteger
    //    cellaaa.textLabel.text=[NSString stringWithFormat:@"6666---%zd",indexPath.row];
    //    NSLog(@"%p-%zd",cellaaa,indexPath.row);
        
    //    1.根据cell的标识去缓存池中查找可循环利用的Cell
        UITableViewCell *cellaaa=[tableView dequeueReusableCellWithIdentifier:@"a"];
    //    2.如果cell为nil(缓存池找不到对应的cell)
        if(cellaaa==nil){
            cellaaa=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"a"];
    //        cellaaa.textLabel.text=[NSString stringWithFormat:@"testdta---%zd",indexPath.row];
        }
    //    3.覆盖数据
        cellaaa.textLabel.text=[NSString stringWithFormat:@"testdata---%zd",indexPath.row];
        
        return cellaaa;
    }
    @end

     

  • 相关阅读:
    主线程MainThread与渲染线程RenderThread
    杀死进程的几种方式
    Android App的设计架构:MVC,MVP,MVVM与架构经验谈
    动画完全解析(二):补间动画原理及自定义动画
    SublimeText教程
    JqGrid自定义的列
    js 除法 取整
    js日期字符串增加天数的函数
    Oracle中的rownum和rowid
    jQuery判断对象是否是函数
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/6057088.html
Copyright © 2011-2022 走看看