如何处理工具栏中的 IQKeyboardManager 完成按钮操作?

How to Handle IQKeyboardManager Done button action in toolbar?

我是新手 ios 我在 iqkeyboardmanager 工作,我想访问 IQKeyboardManager 中的完成按钮操作。

你可以使用 UITextViewDelegate

func textFieldDidEndEditing(_ textField: UITextField) {

 }

您可以处理完成、下一个和上一个按钮的点击

[textField.keyboardToolbar.previousBarButton setTarget:self action:@selector(previousAction:)];
[textField.keyboardToolbar.nextBarButton setTarget:self action:@selector(nextAction:)];
[textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];

在swift中:

customField.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(doneButtonClicked))

func doneButtonClicked(_ sender: Any) {
        //your code when clicked on done
}

我会尽量用更方便的方式描述:

import IQKeyboardManagerSwift

class EditPostViewCell: UITableViewCell {

   @IBOutlet weak var commentTextView: UITextView!


   override func awakeFromNib() {
      IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "Send Comment"
      commentTextView.delegate = self
   }

   @objc func didPressOnDoneButton() {
      commentTextView.resignFirstResponder()
      sendComment()
   }

}

extension EditPostViewCell: UITextViewDelegate {

   public func textViewDidBeginEditing(_ textView: UITextView) {
      let invocation = IQInvocation(self, #selector(didPressOnDoneButton))
      textView.keyboardToolbar.doneBarButton.invocation = invocation
   }
}

您可以导入

import IQKeyboardManager

在所需的文件中,然后是

vc1Textfield.addDoneOnKeyboard(withTarget: self, action: #selector(doneButtonClicked))

这里的 vc1Textfield 是我的文本域,doneButtonClicked 的定义如下:

@objc func doneButtonClicked(_ sender: Any) { }

希望对大家有所帮助!!!快乐编码....

首先: import the IQKeyboardManager.h

然后:

[self.textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];

xcode 11. 使用代码创建 A​​ction 连接 textField。

@IBAction func yourName(_ sender: Any){
// Your code
} 

Connections inspector screen