没有带有 UIAlertViewStylePlainTextInput 的键盘?
我的 UIAlertViewStylePlainTextInput 有问题。我收到带有文本字段的警报,但没有出现键盘..?这是我的代码:
UIAlertView *enter = [[UIAlertView alloc] initWithTitle:@"Highscores" message:@"Please Enter Your Name" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Abbrechen" nil];
enter.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *theTextField = [enter textFieldAtIndex:0];
theTextField.placeholder = @"Your Name";
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
theTextField.selected = NO;
[enter show];
我尝试过不使用该
UITextField *theTextField = [enter textFieldAtIndex:0];
theTextField.placeholder = @"Your Name";
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
theTextField.selected = NO;
部件,但仍然没有键盘出现。
(我已经在我的设备和模拟器上对其进行了测试)
您对此有什么想法吗?
先感谢您。
I have a problem with the UIAlertViewStylePlainTextInput. I get my Alert with the textfield but there is no Keyboard coming up..? Here is my code:
UIAlertView *enter = [[UIAlertView alloc] initWithTitle:@"Highscores" message:@"Please Enter Your Name" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Abbrechen" nil];
enter.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *theTextField = [enter textFieldAtIndex:0];
theTextField.placeholder = @"Your Name";
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
theTextField.selected = NO;
[enter show];
I have tried without the
UITextField *theTextField = [enter textFieldAtIndex:0];
theTextField.placeholder = @"Your Name";
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
theTextField.selected = NO;
part but still there is no keyboard coming up.
(I've tested it on my device and on the simulator)
Do you have any ideas about that?
thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了问题,因为当在我的视图中调用 UITextField 委托方法 textFieldDidBeginEditing 时触发警报,然后我将用警报视图文本字段的内容填充它。这意味着我认为 UITextField 成为了第一响应者,而我找不到辞职的方法。因此,如果您遇到问题,那是因为在显示 UIAlert 之前有其他东西正在成为第一响应者。考虑一下如何触发警报。
我放弃在 UITextField 上使用点击手势,然后使用 UIAlertViewStylePlainTextInput 触发 UIAlertView,并且工作正常。
下面的一些代码:
I had the problem because I was triggering the alert when a UITextField delegate method textFieldDidBeginEditing was called in my view and then I would fill this with the content of the Alert view text field. That meant that the UITextField in my view became first responder and I couldn't find a way to resign. So if you have the problem it is because something else is becoming first responder before the UIAlert is displayed. Think about how you trigger the alert.
I resigned to using a tap gesture on my UITextField which then triggers the UIAlertView with UIAlertViewStylePlainTextInput and it works fine.
Some code below:
尝试下面的代码:
适用于 iOS5
Try below code:
Works on iOS5
可能会解决你的问题,因为它解决了我的问题:
Might fix your problem as it solved mine: