I am new in ios I work on iqkeyboardmanager and I want to access Done button action in IQKeyboardManager.
Asked
Active
Viewed 2.5k times
20
-
Well i dont think you can handle the done button from IQKeyboard but if you want to perform something you can put you custom action on the `Return key` in the keyboard – cpt. Sparrow Oct 26 '17 at 09:40
-
but i want handle Done button action as well – Berlin Oct 26 '17 at 09:43
6 Answers
40
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
}

Kumar
- 1,882
- 2
- 27
- 44
-
I got error in swift "Value of type 'UITextField' has no member 'keyboardToolbar'" while using above method – bittu Aug 29 '18 at 06:59
-
@Lalit Kumar i am getting this error - Property 'keyboardToolbar' not found on object of type 'IQDropDownTextField *' – R. Mohan Dec 24 '18 at 10:29
-
1
-
1
18
you can use UITextViewDelegate
func textFieldDidEndEditing(_ textField: UITextField) {
}

PoolHallJunkie
- 1,345
- 14
- 33
-
4But this delegate function is called even if user didn't tap *Done* button. I can just tap the screen and this function will fire too. – Kegham K. Aug 23 '18 at 23:22
-
3This delegate may call from return key of keyboard, so its not good solution. – Jagdeep Singh Sep 27 '18 at 11:42
16
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....

AjinkyaSharma
- 1,870
- 1
- 16
- 26

bittu
- 683
- 7
- 24
6
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
}
}

stosha
- 2,108
- 2
- 27
- 29
0
First:
import the IQKeyboardManager.h
Then:
[self.textField.keyboardToolbar.doneBarButton setTarget:self action:@selector(doneAction:)];

tomerpacific
- 4,704
- 13
- 34
- 52

XiRuo
- 1
0
xcode 11. Make Action connection textField with code.
@IBAction func yourName(_ sender: Any){
// Your code
}

Sergey Davydov
- 21
- 4