问题
I am new in ios I work on iqkeyboardmanager and I want to access Done button action in IQKeyboardManager.
回答1:
you can use UITextViewDelegate
func textFieldDidEndEditing(_ textField: UITextField) {
}
回答2:
You can handle clicks of done, next and previous button
[textField.keyboardToolbar.previousBarButton setTarget:self action:@selector(previousAction:)];
[textField.keyboardToolbar.nextBarButton setTarget:self action:@selector(nextAction:)];
[textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];
In swift:
customField.keyboardToolbar.doneBarButton.setTarget(self, action: #selector(doneButtonClicked))
func doneButtonClicked(_ sender: Any) {
//your code when clicked on done
}
回答3:
You can import
import IQKeyboardManager
in required file and after that
vc1Textfield.addDoneOnKeyboard(withTarget: self, action: #selector(doneButtonClicked))
here vc1Textfield is my textfield and doneButtonClicked definition is given below:
@objc func doneButtonClicked(_ sender: Any) { }
Hope it help someone!!! Happy Coding....
回答4:
I will try to describe in a more convenient way:
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
}
}
回答5:
First:
import the IQKeyboardManager.h
Then:
[self.textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];
回答6:
xcode 11. Make Action connection textField with code.
@IBAction func yourName(_ sender: Any){
// Your code
}
Connections inspector screen
来源:https://stackoverflow.com/questions/46950732/how-to-handle-iqkeyboardmanager-done-button-action-in-toolbar