1
 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没有解决我不知道

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

4

1 回答 1

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"))
于 2018-08-01T12:30:56.327 回答