I have a UIView subclass with an added observer for the UIKeyboardWillShowNotification and UIKeyboardWillHideNotification. This UIView is in a UITableViewCell subclass. I have two other UITableViewCell subclasses that contain UITextFields. When those text fields are tapped, my custom UIView receives those notifications. I have these three UITableViewCell subclasses setup for a email composer view type of thing.
How can I make sure that when my UIView subclass receives the keyboard will show or hide notification that it is for the UIView and not to the other UITableViewCell's that contain ui text fields?
I should mention that I have a UIWebView in my UIView subclass. When a contenteditable div is tapped, I want to receive notification that the keyboard came up but only for my UIWebView instance.
I was thinking I could do the following, but that doesn’t seem to work.
[[NSNotificationCenter defaultCenter] addObserver:self selector@(selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:_webView];
I think it depends for what you need the
UIKeyboardNotification, you can achieve the same thing with:To see when the editing did begin. And this to see when the editing did end:
Don’t forget your
UITableViewCellsmust comply with theUITextFieldDelegateprotocol.Quick reference about the
UITextFieldDelegateprotocol.Edit: One more thing, the solution I gave you makes sense when you have the need to know when a specific
UITextFieldbecame first responder. If you don’t care about that, and you just need to know when the keyboard actually comes and goes, you should notify theUIViewControllerthat have yourUITableViewinstead of each individual cell. TheUIViewControllershould then take the proper action.