IQKeyboardManagerSwift pod install : How to implement Done button action in swift

1.5k views Asked by At

I'm using the following library (which helps to manage multiple textfields)

pod 'IQKeyboardManagerSwift', '~> 4.0'

My question is how would I got about to implement done button action in our viewController ? I refer this link.
In IQUIView+IQKeyboardToolbar.swift file this method is available.

public func addDoneOnKeyboardWithTarget(_ target : AnyObject?, action : Selector) {

        addDoneOnKeyboardWithTarget(target, action: action, titleText: nil)
    }

but I don't understand how to implement in swift code. Please help me..

1

There are 1 answers

1
yogesh wadhwa On

You can call it on any textField object. for example

[textField1 addDoneOnKeyboardWithTarget:@selector(doneAction:)];
/*! doneAction. */
-(void)doneAction:(UIBarButtonItem*)barButton
{
    //doneAction
}

Swift Version:

textField1.addDoneOnKeyboardWithTarget(self, action: #selector(self.doneAction(_:)), shouldShowPlaceholder: true)

func doneAction(_ sender : UITextField!) {
    self.view.endEditing(true)
}