我有SDWebImage的问题,我有一个UICollectionView
,我正在尝试将网址图片转到indexPath
。我被困了似乎我错过了单元格中的一个关键点。对此有任何帮助。我想这是愚蠢的事情,但是嘿..还要提到我有很多网址图片不仅仅是一个
这是我的结构
struct Regions {
let imageName: String
let imageUrl: String
let titleName: String
let action: String
let actionUrl: String
init(imageName: String, imageUrl: String, titleName: String, action: String, actionUrl: String) {
self.imageName = imageName
self.imageUrl = imageUrl
self.titleName = titleName
self.action = action
self.actionUrl = actionUrl
}
}
我的追加方法
actions.append(Regions(imageName: "agorianicam", imageUrl: "http://agorianicam.forecastweather.gr/agorianicam.jpg", titleName: "Αγόριανη", action: "agoriani", actionUrl: "http://5.196.92.163:8080/agoriani.html"))
cellForItemAtIndexPath:
方法
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! RegionListingCollectionCell
// cell.imgView.sd_setImageWithURL.image = UIImage.init(named: actions[indexPath.row].imageUrl)
cell.imgView.image = UIImage.init(named: actions[indexPath.row].imageName)
cell.titleLabel?.text = actions[indexPath.row].titleName
return cell
}
答案 0 :(得分:0)
使用cell.imgView.sd_setImage(with: yourUrl, placeholderImage: anyPlaceholderImage)
而不是分配图像。或者查看SDWebImage Doc了解更多信息。
所以根据你的代码,下面的代码应该适合你:
cell.imgView.sd_setImage(with: URL(string: actions[indexPath.row].imageUrl), placeholderImage: anyPlaceholderImage)