iosmessagekitinputbaraccessoryview

How to clear text in MessageKit inputBar after Pressing Send in inputBarAccessoryView


I'm building a real time chat application. Where I use message kit and inputBarAccessoryView library to make a conversation between 2 users.

I've used -

extension ChatViewController: InputBarAccessoryViewDelegate {
 func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
  // message sending logic
 }
}

this delegate function but when I pressed send button the message is sent but the text is still remain in the inputBar it is not getting cleared.

How can I clear the inputBar text when user click the Send Button?


Solution

  • I've found the solution in this question's answer.

    Adding this line -

    inputBar.inputTextView.text = ""
    

    at the end of the func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) function clears the text after clicking send button.

    extension ChatViewController: InputBarAccessoryViewDelegate {
    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
      // all the message sending logic
    
      // last line
      inputBar.inputTextView.text = ""
     }
    }