【发布时间】:2018-05-02 20:30:11
【问题描述】:
我正在尝试实现 Kingfisher 图像缓存,并将图像托管在我的 UITableView 的 firebase 中。但是我在转换 imageView.kf.setImage.. 的值类型时遇到问题。
我得到的错误是“Cannot convert value of type 'RetrieveImageTask' to type 'UIImageView' in coercion”这与“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
}
}
【问题讨论】:
-
我仍在尝试解决这个问题,但到目前为止还没有结果。仍然停留在同样的错误,
标签: xcode firebase swift4 kingfisher