zoukankan      html  css  js  c++  java
  • 关于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动态填充数据实现。

  • 相关阅读:
    mysql数据库(1)
    通过全局异常处理机制实现接口参数校验返回指定返回类型
    http接口安全校验
    java 锁机制介绍
    通过反射获取类的所有属性值拼接成字符串工具类
    Mybatis中出现java.sql.SQLException: 无效的列类型: 1111
    判断两个Long相等
    jwt工具类
    mybatis #{}和${}的区别是什么
    报错解决NoSuchMethod。。。
  • 原文地址:https://www.cnblogs.com/wenxp2006/p/3086790.html
Copyright © 2011-2022 走看看