0

I have a UINavigationController with two screens - each screen with its own nav controller. The first screen has no entry boxes but the second screen (that is pushed onto the nav controller stack) does have a UITextView in it.

UITextView *commentTextView;

My questions is: How do I make the UIKeyboard disappear when the user uses the back button on the nav controller bar to pop the UIView off the nav controller stack and show the previous screen?

I have tried using [commentTextView resignFirstResponder] in a number of places but it never works. The keyboard is still visible even when the UIView has disappeared.

I've tried putting resignFirstResponder call in:

-(void)viewWillDisappear:(BOOL)animated

of the view and also I've tried registering a notification when the UITextView has finished editing like:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidBeginEditingNotification object:nil];

but again, this doesn't work when the user dismisses the UIView by using the Nav Controller's back button.

I'm not sure if I've described this question brilliantly (my first day on stack overflow!) but does anybody have any ideas on this one?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Damien
  • 2,421
  • 22
  • 38

3 Answers3

3

Are you presenting the view modally? See : iPad keyboard will not dismiss if navigation controller presentation style is “form sheet

Community
  • 1
  • 1
ragamufin
  • 4,113
  • 30
  • 32
0

Perhaps try sending the resignFirstResponder message to your view controller instead of your TextView?

- (void)viewWillDisappear:(BOOL)animated {
    [self resignFirstResponder];
}
Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63
  • Thanks for the hint Ken. Unfortunately no joy. The view controller doesn't have a resignFirstResponder message but the view does so I tried [self.view resignFirstResponder] in the viewWillDisappear method but no luck. But thanks again for the suggestion. – Damien Apr 04 '11 at 22:17
0

Try sending -endEditing: to self in -viewWillDisappear:.

Mark Adams
  • 30,776
  • 11
  • 77
  • 77
  • Thanks Mark. I tried your suggestion but no luck. Looking at the link posted by ragamufin: it's a "feature" by Apple. Now, how do I put the hair I've been pulling out back into my head :-) – Damien Apr 04 '11 at 23:28
  • Ah I see. Apple did expose a new property on `UIViewController` in 4.3 that apparently addresses the issue. The property is `-disablesAutomaticKeyboardDismissal:` and is set to `YES` by default. Worth looking into. – Mark Adams Apr 04 '11 at 23:47