I work with JSQMessagesViewController and Firebase to implement the chat function in my application. Everything was fine in my ChatViewController. But now I have moved my ChatViewController to the container view, which is inside the parent view controller, and now the send button does not work when the keyboard expands.
In other words, to send a chat message, I have to call view.endEditing(true) on the parent view controller, which itself is in the UITabBarController, and then the submit button will work. But while the keyboard expands, the submit button does not respond. below is my ChatViewController code ...
import Foundation import UIKit import FirebaseDatabase import JSQMessagesViewController final class ChatViewController: JSQMessagesViewController { var outgoingBubbleImageView: JSQMessagesBubbleImage! var incomingBubbleImageView: JSQMessagesBubbleImage! var fireRootRef: FIRDatabaseReference! var chatMessages = [JSQMessage]() var messagesRefHandle: UInt! var chatChannelId: String! override func viewDidLoad(){ super.viewDidLoad() self.inputToolbar.contentView.textView.backgroundColor = UIColor.clear inputToolbar.alpha = 0.7 ... } override func viewWillAppear(_ animated: Bool){ super.viewWillAppear(animated) } override func viewDidAppear(_ animated: Bool){ super.viewDidAppear(animated) } func setupView(){ ... } override func viewWillDisappear(_ animated: Bool) { super.viewDidDisappear(animated) removeChatObserver() } func removeChatObserver(){ ... } private func setupMessageBubbles() { ... } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return chatMessages.count } override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource! { let message = chatMessages[indexPath.item] if message.senderId == senderId { return outgoingBubbleImageView } else { return incomingBubbleImageView } } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = super.collectionView(collectionView, cellForItemAt: indexPath) as! JSQMessagesCollectionViewCell let message = chatMessages[indexPath.item] if message.senderId == senderId { cell.textView!.textColor = UIColor.white } else { cell.textView!.textColor = UIColor.black } return cell } override func collectionView(_ collectionView: JSQMessagesCollectionView!, layout collectionViewLayout: JSQMessagesCollectionViewFlowLayout!, heightForMessageBubbleTopLabelAt indexPath: IndexPath!) -> CGFloat { let message = chatMessages[indexPath.item] if message.senderId == self.senderId { return 0 } if indexPath.item > 0 { let previousMessage = chatMessages[indexPath.item - 1] if previousMessage.senderId == message.senderId { return 0 } } return kJSQMessagesCollectionViewCellLabelHeightDefault } override func collectionView(_ collectionView: JSQMessagesCollectionView!, attributedTextForMessageBubbleTopLabelAt indexPath: IndexPath!) -> NSAttributedString! { let message = chatMessages[indexPath.item] switch message.senderId { case senderId: return nil default: guard let senderDisplayName = message.senderDisplayName else { assertionFailure() return nil } return NSAttributedString(string: senderDisplayName) } }
I would like to fix the submit button so that the user can click Submit when expanding the keyboard. Interestingly, in order to reject the keyboard, I have to call view.endEditing(true) on the parent view controller, and not on the child view itself. This made me think that I needed to configure the button action on the parent view, but I did not succeed. Thank you for your help.
Mikeg source share