如果点击了特定内容,我想调用一个函数UITextField
:据我了解,以下代码适用于来自窗口的通知:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
但我想从特定的UITextField
. 我尝试了以下代码但没有成功:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UITextFieldTextDidBeginEditingNotification, object: textField)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UITextFieldTextDidEndEditingNotification, object: textField)
我搜索了很多,在这里发现了同样的问题(Swift 2 addObserver for specific textField with the object parameter),但答案对我不起作用。
我现在正在尝试 3 小时.... 任何帮助表示赞赏,非常感谢!