我正在嘗試在我的Swift 3
項目中使用JSQMessagesVC
。它通過可可豆莢安裝,一切看起來都很好。問題是我無法實現collectionView方法並不斷收到錯誤。誰能幫我?無法實現JSQMessagesViewController所需的方法Swift 3
import UIKit import JSQMessagesViewController class ChatViewController: JSQMessagesViewController { var messages = [JSQMessage]() override func viewDidLoad() { super.viewDidLoad() collectionView!.delegate = self collectionView!.dataSource = self collectionView!.collectionViewLayout.incomingAvatarViewSize = CGSize.zero collectionView!.collectionViewLayout.outgoingAvatarViewSize = CGSize.zero } override func collectionView(_ collectionView: JSQMessagesCollectionView, messageDataForItemAt indexPath: IndexPath) -> JSQMessageData { return messages[indexPath.item] } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return messages.count } override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource! { let message = messages[indexPath.item] // 1 if message.senderId == senderId { // 2 return outgoingBubbleImageView } else { // 3 return incomingBubbleImageView } } override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource! { return nil } lazy var outgoingBubbleImageView: JSQMessagesBubbleImage = self.setupOutgoingBubble() lazy var incomingBubbleImageView: JSQMessagesBubbleImage = self.setupIncomingBubble() private func setupOutgoingBubble() -> JSQMessagesBubbleImage { let bubbleImageFactory = JSQMessagesBubbleImageFactory() return bubbleImageFactory!.outgoingMessagesBubbleImage(with: UIColor.jsq_messageBubbleBlue()) } private func setupIncomingBubble() -> JSQMessagesBubbleImage { let bubbleImageFactory = JSQMessagesBubbleImageFactory() return bubbleImageFactory!.incomingMessagesBubbleImage(with: UIColor.jsq_messageBubbleLightGray()) } // override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { // //Your Logic here // } }
請告訴我們你收到了什麼錯誤 –
甚至實現了我無法擺脫這些消息的方法。我正在嘗試關注Raywenderlich教程https://www.raywenderlich.com/140836/firebase-tutorial-real-time-chat-2 –
您使用的是最新版本的JSQMessagesViewController嗎? –