From ab41cd36e995a81226bec32d0b4c3d32f92fb28a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 23 Oct 2015 11:19:31 +0800 Subject: [PATCH 1/3] default set updateOlderMessagesIfNeeded --- Podfile.lock | 2 +- .../Conversation/ConversationViewController.swift | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 3e881dcf..4f1ab3ae 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -77,4 +77,4 @@ SPEC CHECKSUMS: SocketRocket: ee0b5c34182d37bb4f1f8d628bbe737718126daa TPKeyboardAvoiding: 614ebec846ec28b83d548769297fa5fb56468904 -COCOAPODS: 0.39.0 +COCOAPODS: 0.38.2 diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index e5588f83..b922eaf2 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -888,7 +888,7 @@ class ConversationViewController: BaseViewController { } } - private func batchMarkMessagesAsReaded(updateOlderMessagesIfNeeded updateOlderMessagesIfNeeded: Bool = false) { + private func batchMarkMessagesAsReaded(updateOlderMessagesIfNeeded updateOlderMessagesIfNeeded: Bool = true) { if let recipient = conversation.recipient, latestMessage = messages.last { @@ -896,15 +896,6 @@ class ConversationViewController: BaseViewController { if updateOlderMessagesIfNeeded { -// var x = 0 -// messages.forEach { message in -// if !message.readed { -// x++ -// } -// } -// -// println("x: \(x)") - var predicate = NSPredicate(format: "readed = false", argumentArray: nil) if case .OneToOne = recipient.type { From aa34faeda9708784a763c6d70ca187405ce4a42d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 23 Oct 2015 11:50:29 +0800 Subject: [PATCH 2/3] reloadFeedConversationsTableView when receive new messages --- .../FeedConversationsViewController.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Yep/ViewControllers/FeedConversations/FeedConversationsViewController.swift b/Yep/ViewControllers/FeedConversations/FeedConversationsViewController.swift index da095e30..aa0c49f8 100644 --- a/Yep/ViewControllers/FeedConversations/FeedConversationsViewController.swift +++ b/Yep/ViewControllers/FeedConversations/FeedConversationsViewController.swift @@ -28,6 +28,11 @@ class FeedConversationsViewController: UIViewController { let feedConversationCellID = "FeedConversationCell" + deinit { + + NSNotificationCenter.defaultCenter().removeObserver(self) + } + override func viewDidLoad() { super.viewDidLoad() @@ -48,6 +53,8 @@ class FeedConversationsViewController: UIViewController { } } } + + NSNotificationCenter.defaultCenter().addObserver(self, selector: "reloadFeedConversationsTableView", name: YepNewMessagesReceivedNotification, object: nil) } var isFirstAppear = true From 1994ca8314c8e2ddaf9f21c530c1d4bee75dfc3b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 23 Oct 2015 12:08:12 +0800 Subject: [PATCH 3/3] better logic for simulate select in Feeds --- .../Feeds/FeedsViewController.swift | 17 ++++++++--- Yep/Views/Cells/Feed/FeedCell.swift | 30 +++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index fa724ec6..e4b0cd37 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -344,17 +344,26 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { } // simulate select effects when tap on messageTextView or cell.mediaCollectionView's space part - - cell.touchesBeganAction = { [weak self] in + // 不能直接捕捉 indexPath,不然新插入后,之前捕捉的 indexPath 不能代表 cell 的新位置,模拟点击会错位到其它 cell + cell.touchesBeganAction = { [weak self] cell in + guard let indexPath = tableView.indexPathForCell(cell) else { + return + } self?.tableView(tableView, willSelectRowAtIndexPath: indexPath) tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None) } - cell.touchesEndedAction = { [weak self] in + cell.touchesEndedAction = { [weak self] cell in + guard let indexPath = tableView.indexPathForCell(cell) else { + return + } delay(0.03) { self?.tableView(tableView, didSelectRowAtIndexPath: indexPath) } } - cell.touchesCancelledAction = { + cell.touchesCancelledAction = { cell in + guard let indexPath = tableView.indexPathForCell(cell) else { + return + } tableView.deselectRowAtIndexPath(indexPath, animated: true) } diff --git a/Yep/Views/Cells/Feed/FeedCell.swift b/Yep/Views/Cells/Feed/FeedCell.swift index 9a214dfb..6d5471ab 100644 --- a/Yep/Views/Cells/Feed/FeedCell.swift +++ b/Yep/Views/Cells/Feed/FeedCell.swift @@ -31,9 +31,9 @@ class FeedCell: UITableViewCell { var tapAvatarAction: (() -> Void)? var tapMediaAction: ((transitionView: UIView, imageURL: NSURL) -> Void)? - var touchesBeganAction: (() -> Void)? - var touchesEndedAction: (() -> Void)? - var touchesCancelledAction: (() -> Void)? + var touchesBeganAction: (UITableViewCell -> Void)? + var touchesEndedAction: (UITableViewCell -> Void)? + var touchesCancelledAction: (UITableViewCell -> Void)? var attachmentURLs = [NSURL]() { didSet { @@ -99,24 +99,36 @@ class FeedCell: UITableViewCell { avatarImageView.addGestureRecognizer(tapAvatar) messageTextView.touchesBeganAction = { [weak self] in - self?.touchesBeganAction?() + if let strongSelf = self { + strongSelf.touchesBeganAction?(strongSelf) + } } messageTextView.touchesEndedAction = { [weak self] in - self?.touchesEndedAction?() + if let strongSelf = self { + strongSelf.touchesEndedAction?(strongSelf) + } } messageTextView.touchesCancelledAction = { [weak self] in - self?.touchesCancelledAction?() + if let strongSelf = self { + strongSelf.touchesCancelledAction?(strongSelf) + } } let backgroundView = TouchClosuresView(frame: mediaCollectionView.bounds) backgroundView.touchesBeganAction = { [weak self] in - self?.touchesBeganAction?() + if let strongSelf = self { + strongSelf.touchesBeganAction?(strongSelf) + } } backgroundView.touchesEndedAction = { [weak self] in - self?.touchesEndedAction?() + if let strongSelf = self { + strongSelf.touchesEndedAction?(strongSelf) + } } backgroundView.touchesCancelledAction = { [weak self] in - self?.touchesCancelledAction?() + if let strongSelf = self { + strongSelf.touchesCancelledAction?(strongSelf) + } } mediaCollectionView.backgroundView = backgroundView }