0

我正在构建一个实时聊天应用程序。我使用消息工具包和 inputBarAccessoryView 库在 2 个用户之间进行对话。

我用过——

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

这个委托函数,但是当我按下发送按钮时,消息被发送,但文本仍然保留在 inputBar 中,它没有被清除。

当用户单击发送按钮时,如何清除 inputBar 文本?

4

1 回答 1

0

我在这个问题的答案中找到了解决方案。

添加这一行 -

inputBar.inputTextView.text = ""

func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String)单击发送按钮后,函数结束时清除文本。

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

  // last line
  inputBar.inputTextView.text = ""
 }
}
于 2021-04-28T09:35:58.400 回答