Difficulty making UIKeyboard go away within a UINavigationController
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: H开发者_运维技巧ow 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?
Are you presenting the view modally? See : iPad keyboard will not dismiss if navigation controller presentation style is “form sheet
Perhaps try sending the resignFirstResponder message to your view controller instead of your TextView?
- (void)viewWillDisappear:(BOOL)animated {
[self resignFirstResponder];
}
Try sending -endEditing:
to self in -viewWillDisappear:
.
精彩评论