diff --git a/FayeClient/FayeClient.swift b/FayeClient/FayeClient.swift index c8f9e8366..8c6b03bc3 100644 --- a/FayeClient/FayeClient.swift +++ b/FayeClient/FayeClient.swift @@ -29,7 +29,7 @@ public typealias FayeClientPrivateHandler = (message: FayeMessage) -> Void public class FayeClient: NSObject { public private(set) var webSocket: SRWebSocket? - public private(set)var serverURL: NSURL! + public private(set) var serverURL: NSURL! public private(set) var clientID: String! public private(set) var sentMessageCount: Int = 0 diff --git a/Yep/Services/YepFayeService.swift b/Yep/Services/YepFayeService.swift index 0c18981fb..07c9b6a56 100644 --- a/Yep/Services/YepFayeService.swift +++ b/Yep/Services/YepFayeService.swift @@ -108,7 +108,7 @@ extension YepFayeService { return } - self?.fayeClient.subscribeToChannel(personalChannel) { data in + self?.fayeClient.subscribeToChannel(personalChannel) { [weak self] data in println("receive faye data: \(data)") diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index cd8ac08b2..76795a6be 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -1510,24 +1510,24 @@ final class ConversationViewController: BaseViewController { let newMessagesCount = Int(messages.count - _lastTimeMessagesCount) - let lastDisplayedMessagesRange = displayedMessagesRange - - displayedMessagesRange.length += newMessagesCount - - let needReloadLoadPreviousSection = self.needReloadLoadPreviousSection - // 异常:两种计数不相等,治标:reload,避免插入 if let messageIDs = messageIDs { if newMessagesCount != messageIDs.count { reloadConversationCollectionView() println("newMessagesCount != messageIDs.count") #if DEBUG - YepAlert.alertSorry(message: "请截屏报告!\nnewMessagesCount: \(newMessagesCount)\nmessageIDs.count: \(messageIDs.count): \(messageIDs)", inViewController: self) + YepAlert.alertSorry(message: "请截屏报告!\nnewMessagesCount: \(newMessagesCount)\nmessageIDs.count: \(messageIDs.count)", inViewController: self) #endif return } } + let lastDisplayedMessagesRange = displayedMessagesRange + + displayedMessagesRange.length += newMessagesCount + + let needReloadLoadPreviousSection = self.needReloadLoadPreviousSection + if newMessagesCount > 0 { if let messageIDs = messageIDs { @@ -1538,10 +1538,10 @@ final class ConversationViewController: BaseViewController { if let message = messageWithMessageID(messageID, inRealm: realm), index = messages.indexOf(message) { - let indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: Section.Message.rawValue) - //println("insert item: \(indexPath.item), \(index), \(displayedMessagesRange.location)") + let indexPath = NSIndexPath(forItem: index - displayedMessagesRange.location, inSection: Section.Message.rawValue) + //println("insert item: \(indexPath.item), \(index), \(displayedMessagesRange.location)") - indexPaths.append(indexPath) + indexPaths.append(indexPath) } else { println("unknown message") @@ -1566,8 +1566,7 @@ final class ConversationViewController: BaseViewController { self?.conversationCollectionView.insertItemsAtIndexPaths(indexPaths) - }, completion: { _ in - }) + }, completion: nil) case .Old: // 用 CATransaction 保证 CollectionView 在插入后不闪动 @@ -1596,11 +1595,9 @@ final class ConversationViewController: BaseViewController { }) } - println("insert messages A") + println("insert other messages") } else { - println("self message") - // 这里做了一个假设:本地刚创建的消息比所有的已有的消息都要新,这在创建消息里做保证(服务器可能传回创建在“未来”的消息) var indexPaths = [NSIndexPath]() @@ -1618,10 +1615,9 @@ final class ConversationViewController: BaseViewController { self?.conversationCollectionView.insertItemsAtIndexPaths(indexPaths) - }, completion: { _ in - }) + }, completion: nil) - println("insert messages B") + println("insert self messages") } } diff --git a/Yep/ViewControllers/PickPhotos/ImageCacheController.swift b/Yep/ViewControllers/PickPhotos/ImageCacheController.swift index 3f333aea3..98c15db2e 100644 --- a/Yep/ViewControllers/PickPhotos/ImageCacheController.swift +++ b/Yep/ViewControllers/PickPhotos/ImageCacheController.swift @@ -12,9 +12,9 @@ import Photos final class ImageCacheController { private var cachedIndices = NSIndexSet() - var cachePreheatSize: Int - var imageCache: PHCachingImageManager - var images: PHFetchResult + let cachePreheatSize: Int + let imageCache: PHCachingImageManager + let images: PHFetchResult var targetSize = CGSize(width: 80, height: 80) var contentMode = PHImageContentMode.AspectFill diff --git a/Yep/Views/Cells/QuickPickPhotos/QuickPickPhotosCell.swift b/Yep/Views/Cells/QuickPickPhotos/QuickPickPhotosCell.swift index 261c1224a..7bbe4a4d6 100644 --- a/Yep/Views/Cells/QuickPickPhotos/QuickPickPhotosCell.swift +++ b/Yep/Views/Cells/QuickPickPhotos/QuickPickPhotosCell.swift @@ -20,7 +20,7 @@ final class QuickPickPhotosCell: UITableViewCell { var pickedPhotosAction: (Set -> Void)? var images: PHFetchResult? - let imageManager = PHCachingImageManager() + lazy var imageManager = PHCachingImageManager() var imageCacheController: ImageCacheController! var pickedImageSet = Set() { @@ -40,8 +40,6 @@ final class QuickPickPhotosCell: UITableViewCell { photosCollectionView.registerNibOf(CameraCell) photosCollectionView.registerNibOf(PhotoCell) - photosCollectionView.dataSource = self - photosCollectionView.delegate = self photosCollectionView.showsHorizontalScrollIndicator = false if let layout = photosCollectionView.collectionViewLayout as? UICollectionViewFlowLayout { @@ -63,6 +61,9 @@ final class QuickPickPhotosCell: UITableViewCell { strongSelf.images = images strongSelf.imageCacheController = ImageCacheController(imageManager: strongSelf.imageManager, images: images, preheatSize: 1) + strongSelf.photosCollectionView.dataSource = self + strongSelf.photosCollectionView.delegate = self + strongSelf.photosCollectionView.reloadData() PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(strongSelf)