2014-09-05 85 views
12

我有一个UIAlertView与文本框内(UIAlertViewStylePlainTextInput),它会自动弹出一个键盘在iOS 7中。但是,当我升级到iOS 8时,键盘不会自动弹出式菜单,而不必点击文本框以使键盘弹出。无论如何,当我打电话时,将自动键盘弹出窗口恢复到UIAlertView文本框?UIAlertView与文本框不会弹出键盘在iOS 8

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"" message:@"The amount?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; 
    alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    UITextField * alertTextField = [alert textFieldAtIndex:0]; 
    alertTextField.keyboardType = UIKeyboardTypeNumberPad; 
    [alertTextField setTextAlignment:NSTextAlignmentCenter]; 
    [alert show]; 
    [alert release]; 

更新:[alertTextField becomeFirstResponder];不工作也不

[[alert textFieldAtIndex:0] setDelegate:self]; 
[[alert textFieldAtIndex:0] becomeFirstResponder]; 

此外,还有一个文本框闪烁TextView的,这是有问题的内部指标,因为没有自动弹出,直到实际键盘用户点击文本框本身。

+1

使用UIAlertController运行而不是UIAlertView,因为它在iOS8中不推荐使用,下面是在iOS8中显示警报视图的代码https://developer.apple.com/library/prerelease/ios/samplecode/UICatalog/Introduction/Intro.html – Jageen 2014-09-06 06:52:09

+0

Xcode isn不要让我知道UIAlertView已被弃用... – 2014-09-10 07:35:23

+0

在' - (void)didPresentAlertView:(UIAlertView *)alertView'尝试它# – KudoCC 2014-09-10 07:56:18

回答

0

如果您在[alert show]之后添加此行,它将使键盘弹出。

[alertTextField becomeFirstResponder]; 

希望这有助于

+4

这并没有工作,不幸的是 – 2014-09-05 20:16:53

4

我不得不取消选择“连接硬件键盘”在iPhone模拟器硬件 - >键盘菜单选项,在iOS的8

+0

这也发生在我的实际iOS 8手机上 – 2014-09-13 23:47:24

+0

这解决了我的问题。 – FireDragonMule 2014-09-20 01:47:17