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

解决UITableView上的cell的重用的更多相关文章

  1. iOS之UITableView中的cell因为重用机制导致新的cell的数据出现重复或者错乱

      UITableView中的cell可以有很多,一般会通过重用cell来达到节省内存的目的:通过为每个cell指定一个重用标识符(reuseIdentifier),即指定了单元格的种类,当cell滚 ...

  2. 解决UITableView上计时器(Timer)的滑动问题

    要想计时器(Timer)不因UITableView的滑动而停止工作,就得探讨一下RunLoop了. RunLoop本质和它的意思一样是运行着的循环,更确切的说是线程中的循环.它用来接受循环中的事件和安 ...

  3. 解决UITableView中Cell重用机制导致内容出错的方法总结

    UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...

  4. iOS解决UITableView中Cell重用带来的问题

    tableView的常规配置,当超出一屏的cell就会标上可重用的标识出列到可重用缓存池中,后面再根据可重用标识来到的可重的cell就会和前面显示同样内容. - (UITableViewCell *) ...

  5. UI:UITableView 编辑、cell重用机制

    tableView编辑.tableView移动.UITableViewController tableView的编辑:cell的添加.删除. 使⽤场景: 删除⼀个下载好的视频,删除联系⼈: 插⼊⼀条新 ...

  6. ios之清除cell缓存,解决cell的重用问题。

    tableView表格中的cell有重用机制,这是一个很好的东西,可以避免开辟很多的空间内存.但是有时候我们不想让它重用cell,,可以用以下的代码解决. 将这个代码放在: - (UITableVie ...

  7. UITableView中复用cell显示信息错乱

    UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...

  8. OS开发小记:iOS富文本框架DTCoreText在UITableView上的使用

    要在页面中显示自己的布局,比如文字的字体和颜色.图文并排的样式,我们要用iOS SDK的原生UI在app本地搭建,如果一个页面需要在服务器端获取数据的话,我们也要在本地搭建好固定的布局,解析服务器传回 ...

  9. UITableView中的cell的优化

    1.cell的重用 所谓的cell的重用就是,视图加载的时候只会创建当前视图中的cell,或者比当前视图多一点的cell, 当视图滚动的时候,滚出屏幕的cell会放进缓存中,滚进屏幕的cell会根据I ...

随机推荐

  1. xml转化为Dictionary

    代码 public SortedDictionary<string, object> FromXml(string xml) { SortedDictionary<string, o ...

  2. Fiddler抓包使用教程-安装配置

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/72876628 本文出自[赵彦军的博客] Fiddler是什么? Fiddler是一 ...

  3. Github上删除仓库

    1.先进入到工程里面,然后选择“Settings” 2.将页面拉到最下面,然后点击“Delete this repository”,接着在弹出的窗口中输入需要删除的仓库名. 弹出的窗口如下:

  4. 洛谷4054 [JSOI2009]计数问题

    原题链接 二维树状数组模板题. 对每一种颜色开一棵二维树状数组统计即可. #include<cstdio> using namespace std; const int N = 310; ...

  5. BZOJ 3329 - Xorequ - 数位DP, 矩乘

    Solution 发现 $x \ xor \  2x = 3x$ 仅当 $x$ 的二进制中没有相邻的 $1$ 对于第一个问题就可以进行数位DP 了. 但是对于第二个问题, 我们只能通过递推 打表 来算 ...

  6. MySQL学习笔记-事务相关话题

    事务机制 事务(Transaction)是数据库区别于文件系统的重要特性之一.事务会把数据库从一种一致状态转换为另一个种一致状态.在数据库提交工作时,可以确保其要么所有修改都已经保存了,要么所有修改都 ...

  7. android源码下载/查看地址

    源码下载: http://git.omapzoom.org/ 高通平台android源码下载地址: https://www.codeaurora.org/xwiki/bin/QAEP/WebHome ...

  8. .net调用word转换pdf出现80080005错误的解决办法

    检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80080005. 1:在服务器上安装offi ...

  9. CRC在线计算工具

    http://www.lammertbies.nl/comm/info/crc-calculation.html

  10. rpm安装jdk7

    原文:http://www.centoscn.com/image-text/config/2015/0208/4658.html 系统环境:centos-6.5 安装方式:rpm安装 软件:jdk-7 ...