當表格行進入視圖時,我設法獲取了一些代碼,在其中獲取Instagram圖片的位置(通過Alamofire)。但是,一旦獲取,我不希望再次調用表格行時再次進行調用。我怎樣才能避免這種行爲?當單元格在視圖中時避免再次獲取圖像
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let url = places[indexPath.row].url
if let c = cell as? PlaceTableViewCell {
print("Downloading Image")
Alamofire.request(url, method: .get).responseImage { response in
guard let image = response.result.value else {
print("Error downloading image")
return
}
c.photoImageView.image = image
}
}
}
應該不會是「https://httpbin.org/image.png」,而不是「https://httpbin.org/image/png」 – Miknash
順便說一句。不知道關於AlamoFireImage,謝謝你的領導:) – Miknash
你介意告訴我如何去做我做過的事情,但用AlamofireImage +緩存。我自己嘗試過一次,但由於某種原因無法啓動它 – tommyd456