我正在下载并显示来自AlamofireImage
服务器的缩略图,下载工作正常但是当我滚动tableivew单元格图像一直在变化时,我搜索过并找不到任何解决方案,例如prepareForReuse
在自定义单元格调用。这是我的代码:
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时如何避免图像更改?
答案 0 :(得分:1)
Salman Ghumsani提到here:
我们可以使用Add Your Ui to this Code `enctype = "multipart/form-data"` Code
@using (Html.BeginForm("Action Name", "Control Name", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" id="objPdfFile" value="@Model.PdfFile" name="Obj.PdfFile" />
</select>
<input type="text" id="objName" value="@Model.Name" name="Obj.Name" />
}
扩展名来设置默认缩略图,如下所示:
AlamofireImage
现在滚动表视图时图像没有变化。