我是ios的新手,我在iqkeyboardmanager上工作,我想在IQKeyboardManager中访问完成按钮操作。
您可以处理"完成"、"下一个"和"上一个"按钮的点击
[textField.keyboardToolbar.previousBarButton setTarget:self action:@selector(previousAction:)];
[textField.keyboardToolbar.nextBarButton setTarget:self action:@selector(nextAction:)];
[textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];
在斯威夫特:
customField.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(doneButtonClicked))
func doneButtonClicked(_ sender: Any) {
//your code when clicked on done
}
UITextViewDelegate
func textFieldDidEndEditing(_ textField: UITextField) {
}
你可以导入
import IQKeyboardManager
在所需文件中,之后
vc1Textfield.addDoneOnKeyboard(withTarget: self, action: #selector(doneButtonClicked))
这里 vc1Textfield 是我的文本字段,下面给出了 doneButtonClicked 定义:
@objc func doneButtonClicked(_ sender: Any) { }
希望它对某人有所帮助!!快乐编码....
我将尝试以更方便的方式描述:
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 the IQKeyboardManager.h
然后:
[self.textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];
xcode 11.使操作连接文本字段与代码。
@IBAction func yourName(_ sender: Any){
// Your code
}
连接检查器屏幕