Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Handle IQKeyboardManager Done button action in toolbar?

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

like image 515
Jaydip Avatar asked Oct 26 '17 09:10

Jaydip


4 Answers

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
}
like image 65
Lalit Kumar Avatar answered Nov 02 '22 11:11

Lalit Kumar


you can use UITextViewDelegate

func textFieldDidEndEditing(_ textField: UITextField) {

 }
like image 21
PoolHallJunkie Avatar answered Nov 02 '22 11:11

PoolHallJunkie


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....

like image 16
bittu Avatar answered Nov 02 '22 10:11

bittu


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
   }
}
like image 6
stosha Avatar answered Nov 02 '22 10:11

stosha