ios - UITableViewCell 中的 Swift KingFisher 来自 Url 的图像不是动态的

标签 ios swift uitableview kingfisher

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = chatableView.dequeueReusableCell(withIdentifier: "SendMsgCell", for: indexPath) as! SendMsgTableViewCell
    let msg = chatList[indexPath.row]
    if msg.emoURL != nil{
                cell.sticonFrame.kf.setImage(with: getEmojiFromURL(msg.emoURL!),completionHandler:{
                    (image, error, cacheType, imageUrl) in
                    if image != nil{
                        cell.sticonFrame.alpha = 1
                    }else{
                        cell.sticonFrame.alpha = 0
                        cell.sticonFrame.image = nil
                    }
                })
                cell.layoutIfNeeded()
            }else{
                cell.sticonFrame.alpha = 0
                cell.sticonFrame.image = nil
        }
    return cell
}

KingFisher 无法加载第一个 View

第一次向下滚动看不到图像 如果想看图片,你必须向上滚动后下来

layoutIfNeeded 没有解决,我不知道

一次调用图像后将看到它的动态,

最佳答案

我认为没有任何错误,请检查您的网址不为空,也许图像尺寸太大。

//go for this appoarch
class INSUtilities {
class func setImage(onImageView image:UIImageView,withImageUrl imageUrl:String?,placeHolderImage: UIImage) {

        if let imgurl = imageUrl{
            image.kf.indicatorType = IndicatorType.activity
            image.kf.setImage(with: URL(string: imgurl), placeholder: placeHolderImage, options: nil, progressBlock: nil, completionHandler: { (image, error, cacheType, url) in
            })
        }
        else{
            image.image = placeHolderImage
        }
    }
}

//incellclass call like this

//logoImg is the name of imageView

INSUtilities.setImage(onImageView: cell.sticonFrame, withImageUrl: logo!, placeHolderImage: #imageLiteral(resourceName: "pic_PlaceHolder"))

关于ios - UITableViewCell 中的 Swift KingFisher 来自 Url 的图像不是动态的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626289/

相关文章:

iphone - 在不重新加载的情况下更新 UITableView 中的部分页脚标题

iphone - 带有旧应用程序的 iPhone5 上的黑线

ios - 如何使用 PHAssetResourceRequestOptions progressHandler/PHAssetResourceProgressHandler

ios - 如何在 UICollectionViewDelegateFlowLayout 中设置无间距?

ios - 警告 : Value was defined but never used; consider replacing with a boolean test

ios - 加载数据后在 tableView 中淡入淡出

swift - 为 Tableview 的扩展和折叠效果插入和删除行

ios - UIKit 方法中的 "animated" bool 参数是否与设置动画持续时间不同?

ios - 动态改变 fetchedResultsController

swift - UICollectionView ClipsToBounds=false 无法正常工作