Firebase,UIImageView和Kingfisher缓存 - 转换价值

时间:2017-11-04 12:50:42

标签: xcode firebase swift4 kingfisher

我正在尝试实施Kingfisher图像缓存,其图像托管在我的UITableView的firebase中。但是我在转换imageView.kf.setImage ..

的值类型方面遇到了问题

我得到的错误是“无法将类型'RetrieveImageTask'的值转换为强制类型'UIImageView'”这与“let profileImage = imageView.kf.setImage(with:imageURL)as UIImageView”代码行相关下面。

我似乎不明白imageView.kf.setImage是什么...我希望它是图像视图中的图像...但看起来它是其他东西..

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    guard let cell = tableView.dequeueReusableCell(withIdentifier: "feedCell") as? feedCell else
    {print("dequeueResuableCell return an else"); return UITableViewCell() }


    // data fro userdataArray
    let imageURL = URL(string: userdataArray[indexPath.row].profileImage)
    let imageView = UIImageView()
    let profileImageView = imageView.kf.setImage(with: imageURL) as UIImageView
    let profileName = userdataArray[indexPath.row].name


    // data from activityArray
    let activityDate = "8 October"
    let distance = "8 km"
    let activityName = "test"
    let sightings = "20"
    let kills = "10"


    // Border styling
    // cell.addBottomBorderWithColor(color: UIColor.lightGray, width: 0.5)
    cell.clipsToBounds = true

    // Shadow styling
    cell.layer.shadowColor = UIColor.darkGray.cgColor
    cell.layer.shadowOpacity = 0.25
    cell.layer.shadowRadius = 1
    cell.layer.shadowOffset = CGSize(width: 0, height: 1) // shadow on the bottom right
    cell.layer.masksToBounds = false // important to show the shadow

    cell.configureCell(profileImageView: profileImageView, profileName: profileName, activityDate: activityDate, ActivityName: activityName , distance: distance, sightings: sightings, kills: kills)
    return cell
}

configureCell位于单独的视图文件中

import UIKit

class feedCell: UITableViewCell {

@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var profileName: UILabel!
@IBOutlet weak var activityDate: UILabel!
@IBOutlet weak var name: UILabel!
@IBOutlet weak var distance: UILabel!
@IBOutlet weak var sightings: UILabel!
@IBOutlet weak var kills: UILabel!

func configureCell(profileImageView: UIImageView, profileName: String, activityDate: String, ActivityName: String, distance: String, sightings: String, kills: String) {
    self.profileImage = profileImageView
    self.profileName.text = profileName
    self.activityDate.text = activityDate
    self.name.text = ActivityName
    self.distance.text = distance
    self.sightings.text = sightings
    self.kills.text = kills
}

}

1 个答案:

答案 0 :(得分:1)

您无法使用“imageView.kf.setImage(with:imageURL)作为UIImageView”声明profileImageView,因为它不会返回任何内容。

你需要这样做;

let profileImageView = UIImageView()
profileImageView.kf.setImage(with: imageURL)