Note that there are some explanatory texts on larger screens.

plurals
  1. POUIKeyboardWillHide not triggered
    primarykey
    data
    text
    <p>I read many post here about this topic, but I wasn't able to find an answer to my question, so, hope you won't be bored about another UIKeyboard post :-) </p> <p>In my view controller's implementation I added <code>self</code> as an observer for the two notifications <code>UIKeyboardWillShowNotification</code> and <code>UIKeyboardWillHideNotification</code>, passing the selectors <code>keyboardWillShow:</code> and <code>keyboardWillHide:</code> to handle to notifications. As I touch a <code>UITextField</code>, the <code>keyboardWillShow:</code> method is called but when I press a "Done" button (which dismisses the keyboard) the <code>keyboardWillHide:</code> method is not called. </p> <p>Really, I'd like to make my <code>UITextField</code> show a keyboard with the "hide button" on the bottom right of the keyboard, but I wasn't able to find the right keyboard type. Maybe I need to set the textfield retuntype to "...Done". In that way I saw that "return" key turns to "done". </p> <p>So I set a toolbar to be my <code>UITextField</code>'s <code>inputAccessoryView</code>, so now I can show a standard keyboard with a tool bar above with the "Done" button. As a user touches that button, I hide the keyboard with the <code>resignFirstResponder</code> method. </p> <p>The strange thing is that when I call <code>resignFirstResponder</code>, the <code>UIKeyboardWillHideNotification</code> isn't posted; at least the <code>keyboardWillHide:</code> method is not called.</p> <p>What do you suggest to me? I really wanted to display a keyboard with the small button with the down arrow to hide the keyboard, but also this solution could be right, but I'd like to resize the view and to do this I need to observer <code>UIKeyboardWillHideNotification</code>.</p> <p>Thank you very much for help... </p> <p>(ADDED:) </p> <p>In <code>viewDidLoad</code>:</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:[[self view] window]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:[[self view] window]]; </code></pre> <p>I took these declarations from one of "yours" post :-) But the willShow works... </p> <p>The action of the "Done" button that's in the <code>UIToolbar</code> that's assigned to be the <code>inputAccessoryView</code> of my text field is:</p> <pre><code>-(void)keyboardDone { [msgTextField resignFirstResponder]; </code></pre> <p>CLOSED: OK! When a developer is stupid... it is stupid :-) :-) </p> <p>This is my corrected willHide method:</p> <pre><code>-(void)keyboardWillHide:(NSNotification*)n { NSDictionary* userInfo; CGSize keyboardSize; CGRect viewFrame; /* This was the bad guy :) I forgot to delete it * after I previously copied the willShow method that * checks if keyboard is already shown (if so returns). * * if( keyboardIsShown ) * return; */ userInfo = [n userInfo]; keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; viewFrame = [[self scrollView] frame]; viewFrame.size.height += ( keyboardSize.height - TABBAR_HEIGHT ); [UIView beginAnimations:nil context:NULL]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationDuration:0.5]; [[self scrollView] setFrame:viewFrame]; [UIView commitAnimations]; keyboardIsShown = NO; NSLog(@"HIDE\n"); } </code></pre> <p>First of all I'd like to thank you all for this useless work in helping me. I'd like to give you some points, so I'll try to rise a "interest point" for each answer, but I need to choose the right one... hard part... :-) </p> <p>Excuse me again... I really didn't see the if() statement... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload