我的圖片和一些標籤位於我的單元格內。如果我的頁面上有更多的單元格,那麼向下滾動然後備份會立即加載不同的圖像,然後加載原始照片。我已經閱讀了各地的StackOverflow看看什麼會在我的情況下工作,但到目前爲止我找不到任何東西,因爲我的UITableView是在一個ViewController內。UITableViewCell中的圖像在向下滾動並備份後發生變化
這裏是我我的內容加載到我的手機:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! PostTableViewCell
// Configure the cell...
let post = self.posts[indexPath.row] as! [String: AnyObject]
cell.titleLabel.text = post["title"] as? String
cell.priceLabel.text = post["price"] as? String
if let imageName = post["image"] as? String {
let imageRef = FIRStorage.storage().reference().child("images/\(imageName)")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in if error == nil {
let image = UIImage(data: data!)
UIView.animate(withDuration: 0.4, animations: {
cell.titleLabel.alpha = 1
cell.postImageView.alpha = 1
cell.priceLabel.alpha = 1
cell.postImageView.image = image
})
} else {
print("Error occured during image download: \(error?.localizedDescription)")
}
})
}
return cell
}
有什麼辦法我可以改變tableView.dequeueReusableCell
的東西不同,所以不會發生這種情況?
用'willDisplayCell'方法嘗試設置圖像 –
爲什麼要爲圖像設置動畫效果?只需在動畫之前設置它。 –
@AdrianBobrowski我應該設置整個函數來使用willDisplayCell嗎? – gabe