I am currently working with UITextField
with an inputview - UIPickerView
and I have added a done button to the top the UIPickerView
. I can close the picker view with the done button by resigning the first responder of the textfield from the view controller class using
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ViewController.dismissPickerView))
func dismissPickerView() {
myTextField.resignFirstResponder
}
The problem is that I want to call a function out side the viewController class that resigns the first responder on the myTextField
like below
func doneButton (viewcontroller: UIViewController,textfield:UITextField) {
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(textfield.resignFirstResponder))
}
so I can use it for multiple picker views but I don't know how to implement the SELECTOR OF THE "func doneButton
"
ANY FEEDBack will HELP
You create a helper singleton class, which will be observing to UITextFieldTextDidBeginEditingNotification,UITextFieldTextDidEndEditingNotification. Store/Clear reference of text field or any other first-responder object when notification is fired
Add a static or object method to the singleton class which will be resigning first responder on the object previously stored from notification
Swift 3.0