Reputation:
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];
Upvotes: 1
Views: 954
Reputation: 25927
I think it depends for what you need the UIKeyboardNotification
, you can achieve the same thing with:
- (void)textFieldDidBeginEditing:(UITextField *)textField
To see when the editing did begin. And this to see when the editing did end:
- (void)textFieldDidEndEditing:(UITextField *)textField
Don't forget your UITableViewCells
must comply with the UITextFieldDelegate
protocol.
Quick reference about the UITextFieldDelegate
protocol.
Edit: One more thing, the solution I gave you makes sense when you have the need to know when a specific UITextField
became 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 the UIViewController
that have your UITableView
instead of each individual cell. The UIViewController
should then take the proper action.
Upvotes: 1