문제

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 ???

도움이 되었습니까?

해결책

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

다른 팁

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");

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top