From 5d3fe3124d84c5056fdce812fdffcba13723a54f Mon Sep 17 00:00:00 2001 From: nixzhu Date: Mon, 7 Dec 2015 16:16:43 +0800 Subject: [PATCH] make sure needReloadData after updateFeeds --- Yep/Caches/ImageCache.swift | 4 +-- .../Feeds/FeedsViewController.swift | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Yep/Caches/ImageCache.swift b/Yep/Caches/ImageCache.swift index bbc388fa..56aa27d0 100644 --- a/Yep/Caches/ImageCache.swift +++ b/Yep/Caches/ImageCache.swift @@ -40,7 +40,7 @@ class ImageCache { let attachmentOriginKey = "attachment-0.0-0.0-\(attachmentURL.absoluteString)" let attachmentSizeKey = "attachment-\(cacheSize.width)-\(cacheSize.height)-\(attachmentURL.absoluteString)" - + let OptionsInfos: KingfisherManager.Options = (forceRefresh: false, lowPriority: false, cacheMemoryOnly: false, shouldDecode: false, queue: cacheAttachmentQueue, scale: UIScreen.mainScreen().scale) //查找当前 Size 的 Cache @@ -49,8 +49,6 @@ class ImageCache { if let image = image?.decodedImage() { dispatch_async(dispatch_get_main_queue()) { completion(url: attachmentURL, image: image, cacheType: type) - - Kingfisher.ImageCache.defaultCache.storeImage(image, forKey: attachmentSizeKey, toDisk: false, completionHandler: nil) } } else { diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 957ab72b..44eba909 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -439,6 +439,12 @@ class FeedsViewController: BaseViewController { if let strongSelf = self { + let newFeeds = feeds + + var needReloadData = false + + needReloadData = strongSelf.feeds.isEmpty + if isLoadMore { strongSelf.feeds += feeds @@ -446,10 +452,30 @@ class FeedsViewController: BaseViewController { strongSelf.feeds = feeds } - // 确保有新的才 reload if !feeds.isEmpty { + if newFeeds.count == strongSelf.feeds.count { + + var index = 0 + while index < newFeeds.count { + let newFeed = newFeeds[index] + let oldFeed = strongSelf.feeds[index] + + if newFeed.id != oldFeed.id { + needReloadData = true + break + } + + index += 1 + } + + } else { + needReloadData = true + } + } + + if needReloadData { println("new feeds, reloadData") - strongSelf.feedsTableView.reloadData() // 服务端有新的排序算法,以及避免刷新后消息数字更新不及时的问题 + strongSelf.feedsTableView.reloadData() } } }