画像とラベルがセル内にあります。ページに収まるものよりも多くのセルがある場合は、スクロールダウンして別のイメージを一時的にロードして元の写真をロードします。私は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