问题描述
注意:
从 iOS 4.3 开始,请参阅已接受的答案(不是最高投票的答案).
See accepted answer (not top voted one) for solution as of iOS 4.3.
这个问题是关于在 iPad 键盘中发现的一个行为,如果它在带有导航控制器的模式对话框中显示,则它拒绝被关闭.
This question is about a behavior discovered in the iPad keyboard, where it refuses to be dismissed if shown in a modal dialog with a navigation controller.
基本上,如果我使用以下行显示导航控制器:
Basically, if I present the navigation controller with the following line as below:
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
键盘拒绝被解雇.如果我注释掉这一行,键盘就会消失.
The keyboard refuses to be dismissed. If I comment out this line, the keyboard goes away fine.
...
我有两个文本字段,用户名和密码;用户名有一个下一步按钮,密码有一个完成按钮.如果我在模态导航控制器中显示它,键盘不会消失.
I've got two textFields, username and password; username has a Next button and password has a Done button. The keyboard won't go away if I present this in a modal navigation controller.
工作
broken *b = [[broken alloc] initWithNibName:@"broken" bundle:nil];
[self.view addSubview:b.view];
不起作用
broken *b = [[broken alloc] initWithNibName:@"broken" bundle:nil];
UINavigationController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:b];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[b release];
如果我删除导航控制器部分并将b"本身作为模态视图控制器呈现,它就可以工作.是导航控制器的问题吗?
If I remove the navigation controller part and present 'b' as a modal view controller by itself, it works. Is the navigation controller the problem?
工作
broken *b = [[broken alloc] initWithNibName:@"broken" bundle:nil];
b.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:b animated:YES];
[b release];
工作
broken *b = [[broken alloc] initWithNibName:@"broken" bundle:nil];
UINavigationController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:b];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[b release];
推荐答案
在以模态呈现的视图控制器中,只需覆盖 disablesAutomaticKeyboardDismissal
即可返回 NO
:
In the view controller that is presented modally, just override disablesAutomaticKeyboardDismissal
to return NO
:
- (BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
这篇关于如果模态 ViewController 呈现样式是 UIModalPresentationFormSheet,iPad 键盘不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!