zoukankan      html  css  js  c++  java
  • 解决UITableView上的cell的重用

    1.通过为每个cell指定不同的重用标识符(reuseIdentifier)来解决

    //        static NSString *rankCellIndefier = @"rankCell";
            NSString *cellMark = [NSString stringWithFormat:@"%ld", indexPath.row];
            
            NewsCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellMark];
            tableView.rowHeight = 80;
            if (cell == nil) {
                cell = [[[NewsCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellMark] autorelease];
               if (indexPath.row < 3) {
                      UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
                    imageView.tag = 100 + indexPath.row;
                    [cell addSubview:imageView];
                   [imageView release];
               }
            }
            if (indexPath.row < 3) {
                UIImageView *imageView = (UIImageView *)[cell viewWithTag:100 + indexPath.row];
                imageView.image = [UIImage imageNamed:rankingArray[indexPath.row]];
            }
            cell.titleLabel.text = news.headLineTitle;
            [cell resetLabelFrame:news.headLineTitle];
            cell.dateLabel.text = news.headLineDate;
            cell.rightCountLabel.text = news.headLineCount;
            [pictureAsy pictureCustom:cell imageUrl:news.headLinePhoto indexImage:0];
            return cell;  
        }

    删除重用cell的所有子视图

    这个方法是通过删除重用的cell的所有子视图,从而得到一个没有特殊格式的cell,供其他cell重用。

     

    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
    2. {  
    3.     static NSString *CellIdentifier = @"Cell";  
    4.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell  
    5.     if (cell == nil) {  
    6.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];  
    7.     }  
    8.     else  
    9.     {  
    10.         //删除cell的所有子视图  
    11.         while ([cell.contentView.subviews lastObject] != nil)  
    12.         {  
    13.             [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  
    14.         }  
    15.     }  
    16.     //...其他代码  
    17. }

     

     

     
  • 相关阅读:
    ajax traditional
    阿里云OSS NET SDK 引用示范程序
    js对象的两种写法
    BZOJ NOIP提高组十连测第一场
    ikbc 时光机 F87 Ctrl 失灵 解决办法
    【读书笔记】阅读的危险
    51nod 1118 机器人走方格 解题思路:动态规划 & 1119 机器人走方格 V2 解题思路:根据杨辉三角转化问题为组合数和求逆元问题
    【算法】求逆元模板
    【复习资料】软件工程之快速原型模型
    VirtualBox安装linux mint教程
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4220533.html
Copyright © 2011-2022 走看看