20

I am new in ios I work on iqkeyboardmanager and I want to access Done button action in IQKeyboardManager.

cpt. Sparrow
  • 415
  • 8
  • 22
Berlin
  • 2,115
  • 2
  • 16
  • 28
  • 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 Answers6

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
18

you can use UITextViewDelegate

func textFieldDidEndEditing(_ textField: UITextField) {

 }
PoolHallJunkie
  • 1,345
  • 14
  • 33
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
} 

Connections inspector screen