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动态填充数据实现。

  • 相关阅读:
    怎样让人的一生价值最大
    [LeetCode][Java] Minimum Depth of Binary Tree
    KVC和KVO
    js获取单独一个checkbox是否被选中
    It&#39;s not a Bug, It&#39;s a Feature! (poj 1482 最短路SPFA+隐式图+位运算)
    超声波测距温度补偿
    系统封装接口层 cmsis_os
    STM32F4XX高效驱动篇2 I2C
    Stm32f103 ADC 学习笔记
    Stm32f103 DAC 学习笔记
  • 原文地址:https://www.cnblogs.com/wenxp2006/p/3086790.html
Copyright © 2011-2022 走看看