iOS 7:离开模态ViewController后键盘没有显示 [英] iOS 7: Keyboard not showing after leaving modal ViewController
问题描述
我有一个 HomeViewController
,它与其他几个 UIViewControllers
有不同的模态segue。如果我试图在HomeView中的 UITextField
上显示键盘,一切正常。但是,如果我尝试在从任何模态视图返回后在 UITextField
(使用 becomeFirstResponder
)上显示键盘控制器,键盘从不显示。
I've got a HomeViewController
that has different modal segues to several other UIViewControllers
. If I try to show the keyboard on a UITextField
within the HomeView, everything works fine. However, if I try to show the keyboard on a UITextField
(using becomeFirstResponder
) after returning from any of the modal View Controllers, the keyboard never shows.
以下是我试过的其中一个设置的示例代码:
Here's some sample code from one of the setups I've tried:
在 HomeViewController
:
- (void)viewDidAppear:(BOOL)animated
{
static BOOL firstTimeComplete = false;
if (!firstTimeComplete) {
firstTimeComplete = true;
} else {
UITextField *textField = [[UITextField alloc] init];
[self.view addSubview:textField];
[textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:3]
}
}
在 ModalViewController
:
- (IBAction)done:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
其中已完成:
通过内部补充事件链接到完成按钮。
Where done:
is linked to the "Done" button via a touch up inside event.
我尝试过的一些事情:
- 将模态segues转换为推送segues修复了问题,但我不想在任何子视图中使用导航栏
- 我是在解雇
模态视图控制器时尝试禁用和启用动画(使用dismissViewControllerAnimated:
) - 在故事板中使用展开segue而不是以编程方式进行
任何人都知道可能会发生什么?
Anyone have an idea of what may be going on?
推荐答案
在删除大量代码后,我终于发现正在使用自定义NavigationController,这是根本原因:
After deleting tons of code, I finally found out that a custom NavigationController was being used and this was the root cause:
@implementation MSLNavigationController
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
@end
该应用不需要这段代码,所以我已经核了这个文件。 (但是解释为什么这会隐藏键盘会很棒:))
The app doesn't need this code, so I've nuked the file. (But an explanation as to why this would be hiding the keyboard would be awesome :))
这篇关于iOS 7:离开模态ViewController后键盘没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!