Question

I have a UIView which contains UITexView and a Button. I have a delegate UITextViewDelegate.

When I first set the cursor on the UITextView, the delegate function "textViewShouldEndEditing" gets called, and this function triggers the UIKeyboardWillShowNotification notification. So far so good.

When I click on the button, I call the function [self.textView resignFirstResponder];, this function then calls the delegate "textViewShouldEndEditing", but the notification UIKeyboardWillHideNotification never gets called.

I have a listener for the notification

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(_keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];

Is there anything missing ???

Was it helpful?

Solution

[self.view endEditing:YES]; is the trick, Thank you all for your help

OTHER TIPS

you should post a notification to the notification center in the following way

[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification" object:self];

and you can check whether the notification has received or not in the following way

if ([[notification name] isEqualToString:@"TestNotification"]) NSLog (@"Successfully received the test notification!");

Is your code is like this, check and let me know

-(void)viewDidAppear:(BOOL)animated{
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillHide:)
                                                     name:UIKeyboardWillHideNotification
                                                   object:nil];

}

-(void) keyboardWillHide:(NSNotification *)note{
        NSLog(@"test");

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top