在 inputBarAccessoryView 中按下发送后如何清除 MessageKit inputBar 中的文本

Posted

技术标签:

【中文标题】在 inputBarAccessoryView 中按下发送后如何清除 MessageKit inputBar 中的文本【英文标题】:How to clear text in MessageKit inputBar after Pressing Send in inputBarAccessoryView 【发布时间】:2021-04-28 07:40:42 【问题描述】:

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

我用过-

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

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

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

【问题讨论】:

【参考方案1】:

我在this question's answer找到了解决方案。

添加这一行 -

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

【讨论】:

以上是关于在 inputBarAccessoryView 中按下发送后如何清除 MessageKit inputBar 中的文本的主要内容,如果未能解决你的问题,请参考以下文章