ios – 可重复使用的细胞旧图像显示

ios – 可重复使用的细胞旧图像显示,第1张

概述我从上到下滚动时遇到问题,然后我的tableview可重复使用的单元格显示图像,直到新图像下载完成. 它应显示我的默认图像占位符,直到下载完成后下载新图像,然后将imageview从图像占位符更改为当前下载图像.我该怎么办 ? 抱歉英语不好.如果您需要任何信息,请告诉我们,谢谢 更新 TableViewcontroller: func tableView(_ tableView: UITable 我从上到下滚动时遇到问题,然后我的tablevIEw可重复使用的单元格显示旧图像,直到新图像下载完成.

它应显示我的默认图像占位符,直到下载完成后下载新图像,然后将imagevIEw从图像占位符更改为当前下载图像.我该怎么办 ?

抱歉英语不好.如果您需要任何信息,请告诉我们,谢谢

更新

tableVIEwcontroller:

func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {       let cell = tableVIEw.dequeueReusableCell(withIDentifIEr: "ItemtableVIEwCell") as! ItemtableVIEwCell        let itemInfo = itemInfos[indexPath.row]        var image1 : UIImage?        var image2 : UIImage?        if let imgurl1 = itemInfo.imageUrl  {             image1 = ItemListVIEwController.imageCache.object(forKey: imgurl1 as AnyObject) as? UIImage        }      if let imgurl2 = itemInfo.cookerProfilePicUrl{         image2 = ItemListVIEwController.imageCache.object(forKey: imgurl2 as AnyObject) as? UIImage        }        cell.configureCell(iteminfo: itemInfo,img1 : image1,img2 : image2)        return  cell    }

厦门国际银行:

func configureCell(iteminfo:ItemInfo,img1 : UIImage?,img2 : UIImage? ){        if img1 != nil {            imageVIEwItemPic.image = img1        }        else{            print("hi1")            imageVIEwItemPic.setimageFromURL(url: iteminfo.imageUrl!)        }        if img2 != nil {            imageVIEwCookerProfilePic.image = img2        }        else{            imageVIEwCookerProfilePic.setimageFromURL(url: iteminfo.cookerProfilePicUrl!)        }        labelitemheading.text = iteminfo.heading        labelitemDescription.text = iteminfo.description    }

更新:

overrIDe func awakeFromNib() {        super.awakeFromNib()        self.imageVIEwItemPic.image = UIImage(named: "resto-placeholder.png")    }

更新:

extension UIImageVIEw {    func setimageFromURL(url: String) {        dispatchQueue.global().async {            let data = NSData.init(contentsOf: NSURL.init(string: url) as! URL)            dispatchQueue.main.async {                let image = UIImage.init(data: data as! Data)                ItemListVIEwController.imageCache.setobject(image!,forKey: url as AnyObject)                self.image = image            }        }    }}
解决方法 由于它是一个可重复使用的单元格,它确实“重用”了旧图像的单元格.然后,每次在cellForRowAtIndexPath中显示单元格时,您需要更新它:

func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {        cell.image=placeholder_image        //then download image}
总结

以上是内存溢出为你收集整理的ios – 可重复使用的细胞旧图像显示全部内容,希望文章能够帮你解决ios – 可重复使用的细胞旧图像显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1073006.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存