【问题标题】:endEditing of the keyboard when return button is tapped当点击返回按钮时键盘的结束编辑
【发布时间】:2017-06-21 16:41:52
【问题描述】:

我正在使用 JSQMessageViewController,当用户点击键盘上的返回按钮时,我需要结束键盘的编辑,而是在文本字段中添加“\n”。我已经浏览了 JSQMessageViewController.m、JSQMessagesInputToolbar.m 但没有得到任何文本字段函数 textfieldShouldReturn。

【问题讨论】:

  • 可能由于textfield的returnKeyType?
  • @user3349433 我也试过了。我添加了委托方法 textfieldShouldReturn 并在其中添加了 self.view.endEditing(true) 但我根本没有工作。我将键盘类型更改为 UIKeyboardDone 但它的工作原理相同。

标签: ios swift3 jsqmessagesviewcontroller


【解决方案1】:

我找到了解决办法

override func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    if text == "\n" {
      self.view.endEditing(true)
    }
    return true
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    相关资源
    最近更新 更多