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

823 views Asked by At

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?

1

There are 1 answers

0
mefahimrahman On BEST ANSWER

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 = ""
 }
}