0
我正在下载并从服务器上用AlamofireImage
显示缩略图,下载工作正常,但是当我滚动tableivew单元格图像时,我一直在搜索并找不到任何解决方案,例如prepareForReuse
在自定义的手机中。这里是我的代码:用Alamofire显示桌面单元格图像的问题
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TrendingCell
let trendingIndex = trendingArray[indexPath.row] as! [String:Any]
if let media = trendingIndex["thumbnails"] as? [String:Any] {
if let thumbnail = media["medium"] as? [String:Any] {
thumbnailURL = String(describing:thumbnail["url"]!)
}
}
Alamofire.request(thumbnailURL).responseImage { response in
if let image = response.result.value {
cell.thumbnail.image = image
}
}
return cell
}
如何避免图像更改时,用户滚动tableview?
https://stackoverflow.com/questions/46199203/downloading-uiimage-via-alamofireimage/46199246#46199246 –
我会建议使用[SDWebImage](https://github.com/rs/SDWebImage)库的图像 – Srdjan
您必须将其写入单元格imageView –