UITableViewCell图像中的Swift KingFisher来自URL并非动态

时间:2018-08-01 06:01:30

标签: 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无法加载第一视图

第一次向下滚动看不到图像 如果要查看图像,向上滚动后必须向下走

layoutIfNeeded尚未解决,我不知道

一次调用图片后,它会动态显示,

1 个答案:

答案 0 :(得分:0)

我不认为有任何错误,请检查您的URL是否为空并且图像尺寸是否可能很大。

//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"))