0

我正在尝试实现 Kingfisher 图像缓存,并将图像托管在我的 UITableView 的 firebase 中。但是我在转换 imageView.kf.setImage.. 的值类型时遇到问题。

我得到的错误是“无法将'RetrieveImageTask'类型的值转换为强制类型'UIImageView'”这与下面的“让profileImage = imageView.kf.setImage(with:imageURL)作为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
}

}

4

1 回答 1

1

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

你需要这样做;

let profileImageView = UIImageView()
profileImageView.kf.setImage(with: imageURL)
于 2018-05-02T12:30:11.387 回答