I'd like to call a function if a specific UITextField
was tapped:
As far as I understand the following code works for notifications, which comes from the window:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
But I'd like to have a specific notification from a specific UITextField
. I tried the following code without success:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UITextFieldTextDidBeginEditingNotification, object: textField)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UITextFieldTextDidEndEditingNotification, object: textField)
I searched a lot and found that same question here (Swift 2 addObserver for specific textField with the object parameter), but the answers didn't work for me.
I'm trying that for 3 hours now.... Any help is appreciated, thank you very much!