• 关于UITableView的一点儿新认识


    之前虽然已经学习IOS开发很久了,但是发现好多东西都没有理解到位。今天才彻底弄明白UITableVIewCell的创建过程,所以详细写下来,以供以后参考理解。

    UITableView通过调用方法 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath来生成单元格UITableViewCell,

    而创建生成UITableViewCell的最大个数则有每个cell的高度height和窗口高度screenHeight共同决定,也即生成的cell个数为count=screenHeight/height;

    当count的个数小于需要填充的数据表dataArray的个数时,每次通过重新填充已生成cell的数据来实现内容更新。

    例如:

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

    {

    static NSString *CellString = @"Cell"

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellString];      //   1

    if (cell == nil)

    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CMainCell] autorelease]; // 2
    }

     [cell setData:_data];//3

     return cell;

    }

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {

      CGFloat height;
    return height;  //4
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {     

    return arrayCount;//5

    }

    设定整个手机可视屏幕高度为screenHeight,则程序中执行语句2的次数为screenHeight/height,也就是最多生成这么多个cell。

    如果arrayCount<=(screenHeight/height),生成的cell个数为arrayCount;如果arrayCount>(screenHeight/height),生成的cell个数为screenHeight/height,此时多出的cell通过语句3动态填充数据实现。

  • 相关阅读:
    研究生毕业论文如何选题
    关于虚拟机中开vmnet1(host)后pc不能上网的问题解决
    ubuntu10.04安装x264库
    CentOS 5.5无法识别Atheros AR8151网卡问题解决
    dm365工作笔记20130731
    DAVINCI DM365-DM368开发攻略——U-BOOT-2010.12及UBL的移植
    SQL语法练习
    T-SQL查询语句常用优化技巧总结
    【转】Asp.net控件开发学习笔记整理篇
    【转】Asp.net控件开发学习笔记整理篇
  • 原文地址:https://www.cnblogs.com/wenxp2006/p/3086790.html
Copyright © 2020-2023  润新知