From f423eb8eea61ea9fc92e8bf18a1e667dc7b80257 Mon Sep 17 00:00:00 2001 From: kevinzhow Date: Tue, 14 Apr 2015 14:35:01 +0800 Subject: [PATCH] Fix a crash bug when scroll while playing audo --- .../ConversationViewController.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index d86f6333..a48b3618 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -498,14 +498,14 @@ class ConversationViewController: UIViewController { if let sender = message.fromFriend { if sender.friendState != UserFriendState.Me.rawValue { - let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as! ChatLeftAudioCell - - cell.audioPlayedDuration = currentTime + if let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as? ChatLeftAudioCell { + cell.audioPlayedDuration = currentTime + } } else { - let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as! ChatRightAudioCell - - cell.audioPlayedDuration = currentTime + if let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as? ChatRightAudioCell { + cell.audioPlayedDuration = currentTime + } } } } @@ -876,14 +876,14 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi let indexPath = NSIndexPath(forItem: Int(messages.indexOfObject(playingMessage)), inSection: 0) if let sender = playingMessage.fromFriend { if sender.friendState != UserFriendState.Me.rawValue { - let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as! ChatLeftAudioCell - - cell.playing = false + if let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as? ChatLeftAudioCell { + cell.playing = false + } } else { - let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as! ChatRightAudioCell - - cell.playing = false + if let cell = conversationCollectionView.cellForItemAtIndexPath(indexPath) as? ChatRightAudioCell { + cell.playing = false + } } }