3

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

Grace
  • 1,265
  • 21
  • 47
  • Could you show your _keyboardWillHide method ? – streem Mar 25 '14 at 09:18
  • I'm using Damiaan Twelker's component https://github.com/datwelk/RDRStickyKeyboardView . But I have added the textViewShouldEndEditing delegate to trigger the UIKeyboardWillHideNotification notification – Grace Mar 25 '14 at 09:29
  • You don't have to trigger anything with UIKeyboardWillHideNotification. The point is to register to it, and it will be called whenever you need it. If you use a library i believe you don't even need to register to it, the library does that for you. – streem Mar 25 '14 at 09:37
  • Well the library is only handling the keyboard will show notification, but nothing about the textview resign and keyboard will hide functions! :( – Grace Mar 25 '14 at 09:44
  • The library is handling also handling keyboardwillhide, (line 555). I believe there is some sort of conflict between the two. – streem Mar 25 '14 at 09:52
  • Yeah it is registering the method, but why t will not get called on my textview resign function – Grace Mar 25 '14 at 10:03

3 Answers3

2

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

Grace
  • 1,265
  • 21
  • 47
0

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

yashwanth77
  • 1,820
  • 1
  • 12
  • 17
  • Hi @yashwanth777, I don't want to trigger the notification myself, I want it to get triggered when I resign the uitextview. – Grace Mar 25 '14 at 09:43
  • so when you are resigning textview you post a notification as shown above without posting notification notification center will not be called – yashwanth77 Mar 25 '14 at 09:52
0

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

}
karthik
  • 1,271
  • 1
  • 14
  • 27
  • Yes I have registered my notification, but when I resign the uitextview, the notification is not getting called. – Grace Mar 25 '14 at 09:45
  • I tried the scenario that you told , and it is working for me ,tell me in which method you have register the notification, and also show your _keyboardWillHide implementation – karthik Mar 25 '14 at 09:48
  • I'm using Damiaan Twelker's component github.com/datwelk/RDRStickyKeyboardView . But I have added the textViewShouldEndEditing delegate to trigger the UIKeyboardWillHideNotification notification – Grace Mar 25 '14 at 09:51