UIAlertView的文本字段在iOS8中不显示键盘 [英] UIAlertView's textfield does not show keyboard in iOS8
问题描述
@implementation
UIAlertView *query;
@end
- (void)viewWillAppear:(BOOL)animated {
query = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"New", @"")
message:nil
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"OK", @""), nil];
query.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [_query textFieldAtIndex:0];
textField.placeholder = NSLocalizedString(@"Title", @"placeholder text where user enters name for new playlist");
textField.delegate = self;
[_query show];
}
之后> UIAlertView
是显示,键盘也显示, UITextfield
是焦点(它只适用于iOS7之前,但在iOS8中不起作用)。我试过 [textfield becomeFirstResponder]
,但它没有用。我创建新项目并使用上面的cove,它可以工作。
After UIAlertView
is shown, keyboard is shown too and UITextfield
is focus (It just works on pre iOS7, but does not work in iOS8). I have tried [textfield becomeFirstResponder]
, but it does not worked. I create new project and use cove above, it works.
我的问题:键盘没有显示 UIAlertViewStylePlainTextInput
样式。
My problem: Keyboard does not shown with UIAlertViewStylePlainTextInput
style.
我不知道为什么?任何人都可以帮助我吗?
谢谢。
I don't know why? Can anybody helps me? Thanks.
推荐答案
在调用show后,这个丑陋的黑客为我工作了:
This ugly hack worked for me, after calling show:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// HACKHACK: This is to make the keyboard appear in iOS8
UITextRange* textRange = self.textField.selectedTextRange;
[self.textField selectAll:self];
[UIMenuController sharedMenuController].menuVisible = NO;
self.textField.selectedTextRange = textRange;
});
遇到同样的问题,花了几个小时摆弄UIAlertController,这是正确的解决方案,但不幸的是,其他地方有几个问题(例如,当它从弹出窗口中呈现时会中断),并且不适用于iOS7。
Ran into the same problem, and spent hours fiddling with UIAlertController, which is the "right" solution, but unfortunately has several issues elsewhere (e.g. it breaks when presenting from a popover), and won't work with iOS7.
这绝对是iOS8中的一个错误。我希望Apple尽快解决这个问题。不幸的是,即使使用为iOS7编译的旧二进制文件也可以打破它。
This is definitely a bug in iOS8. I hope Apple fixes this soon. It unfortunately breaks even with older binaries compiled for iOS7.
这篇关于UIAlertView的文本字段在iOS8中不显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!