zoukankan      html  css  js  c++  java
  • UITableViewCell的prepareForReuse方法

    cell被重用怎样提前知道? 重写cell的prepareForReuse官方头文件里有说明.当前已经被分配的cell假设被重用了(一般是滚动出屏幕外了),会调用cell的prepareForReuse通知cell.注意这里重写方法的时候,注意一定要调用父类方法[super prepareForReuse] .这个在使用cell作为网络訪问的代理容器时尤其要注意,须要在这里通知取消掉前一次网络请求.不要再给这个cell发数据了.

    // if the cell is reusable (has a reuse identifier), this is called just before the cell is returned from the table view method dequeueReusableCellWithIdentifier:.  If you override, you MUST call super.

    - (void)prepareForReuse
    {
        [super prepareForReuse];
    }


    自定义UITableViewCell的方法有非常多 发现一些人都会遇到自定义的cell里面图片错乱的问题 这个问题往往是由于没有实现prepareForReuse这种方法导致的.

    UITableViewCell在向下滚动时复用, 得用的cell就是滑出去的那些, 而滑出去的cell里显示的信息就在这里出现了 解决办法就是在UITableViewCell的子类里实现perpareForReuse方法, 把内容清空掉


  • 相关阅读:
    微信mac版的bug 直接显示了消息原始数据
    提一下InfoQ
    成长
    SaaS产品成功学
    .io域名在申请SSL证书时被坑
    一件小事
    Git做代码增量发布的重要用法
    今天
    为什么都不写博
    惑不惑
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7008270.html
Copyright © 2011-2022 走看看