i'm using JSQMessages View Controller third party lib in my app for firebase chat. As following some video and documents i have used all the delegates and datasource methods in my class and name my subclass as JSQMessagesViewController. But when i hit send button i reload the collection view to show messages in collection view but they aren't showing the messages. When i hit send button it send message to firebase database but does not show my message above in collection view. I have commented the button method also and use break points also but nothing is working. How can i show my send messages above in collection view. My code is this,
import UIKit
import Firebase
import FirebaseDatabase
class ChatViewViewController: JSQMessagesViewController {
private var messages = [JSQMessage]()
override func viewDidLoad() {
super.viewDidLoad()
self.senderId = "1"
senderDisplayName="Hamza"
collectionView.reloadData()
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return messages.count
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageDataForItemAt indexPath: IndexPath!) -> JSQMessageData! {
return messages[indexPath.item]
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = super.collectionView(collectionView, cellForItemAt: indexPath) as! JSQMessagesCollectionViewCell
return cell
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource! {
return nil
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource! {
let bubbleFactory = JSQMessagesBubbleImageFactory();
return bubbleFactory?.outgoingMessagesBubbleImage(with:UIColor.blue);
}
override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
messages.append(JSQMessage (senderId: senderId, displayName: senderDisplayName, text: text))
print("Helllo")
collectionView.reloadData()
finishSendingMessage()
}