Manos Chorianopoulos

fix history cell image caching

...@@ -14,6 +14,24 @@ class AnalysisItemViewCell: UITableViewCell { ...@@ -14,6 +14,24 @@ class AnalysisItemViewCell: UITableViewCell {
14 @IBOutlet weak var titleLabel: UILabel! 14 @IBOutlet weak var titleLabel: UILabel!
15 @IBOutlet weak var priceLabel: UILabel! 15 @IBOutlet weak var priceLabel: UILabel!
16 @IBOutlet weak var subtitleLabel: UILabel! 16 @IBOutlet weak var subtitleLabel: UILabel!
17 +
18 + var postImageURL: String? {
19 + didSet {
20 + if let url = postImageURL {
21 + self.itemImage.image = UIImage() // UIImage(named: "loading")
22 +
23 + UIImage.loadImageUsingCacheWithUrlString(url) { image in
24 + // set the image only when we are still displaying the content for the image we finished downloading
25 + if url == self.postImageURL {
26 + self.itemImage.image = image
27 + }
28 + }
29 + }
30 + else {
31 + self.itemImage.image = nil
32 + }
33 + }
34 + }
17 35
18 // lifecycle 36 // lifecycle
19 override func awakeFromNib() { 37 override func awakeFromNib() {
...@@ -42,7 +60,8 @@ extension AnalysisItemViewCell { ...@@ -42,7 +60,8 @@ extension AnalysisItemViewCell {
42 60
43 for merchant in merchantList { 61 for merchant in merchantList {
44 if (merchant._uuid == item._merchant_uuid) { 62 if (merchant._uuid == item._merchant_uuid) {
45 - itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache()) 63 + // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
64 + self.postImageURL = merchant._img_preview
46 titleLabel.text = merchant._admin_name 65 titleLabel.text = merchant._admin_name
47 break; 66 break;
48 } 67 }
...@@ -76,7 +95,8 @@ extension AnalysisItemViewCell { ...@@ -76,7 +95,8 @@ extension AnalysisItemViewCell {
76 95
77 for merchant in merchantList { 96 for merchant in merchantList {
78 if (merchant._uuid == couponSetData?.merchant_uuid) { 97 if (merchant._uuid == couponSetData?.merchant_uuid) {
79 - itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache()) 98 + // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
99 + self.postImageURL = merchant._img_preview
80 titleLabel.text = merchant._admin_name 100 titleLabel.text = merchant._admin_name
81 break; 101 break;
82 } 102 }
......