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. }

     

     

     
  • 相关阅读:
    iOS开发多线程篇—GCD介绍
    IOS UI篇—UILabel的文字顶部对齐
    TableView编辑中实现多行删除的2中方法以及注意
    UITableView的新手——层次注意
    UITabBarItem编写的时候出现得图片显示异常,和有一些比较忽略的方法总结
    在ios开发中nil和NUll和Nilde区别————和如何判断连个对象的关系和UISlider不能拖动的问题
    iphone 手机屏幕和UIView和UIWindowde 的主要的区别
    iOS平常注意1
    ios优化复制大文件时,如何使内存运用最少且效率最高
    property在括号中应该怎样写
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4220533.html
Copyright © 2011-2022 走看看