我的图片和一些标签位于我的单元格内。如果我的页面上有更多的单元格,那么向下滚动然后备份会立即加载不同的图像,然后加载原始照片。我已经阅读了各地的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