没有带有 UIAlertViewStylePlainTextInput 的键盘?

发布于 2024-12-26 13:16:39 字数 860 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与之呼应 2025-01-02 13:16:39

我遇到了问题,因为当在我的视图中调用 UITextField 委托方法 textFieldDidBeginEditing 时触发警报,然后我将用警报视图文本字段的内容填充它。这意味着我认为 UITextField 成为了第一响应者,而我找不到辞职的方法。因此,如果您遇到问题,那是因为在显示 UIAlert 之前有其他东西正在成为第一响应者。考虑一下如何触发警报。

我放弃在 UITextField 上使用点击手势,然后使用 UIAlertViewStylePlainTextInput 触发 UIAlertView,并且工作正常。

下面的一些代码:

-(void)addTextFieldToView{
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 31)];
    textField.backgroundColor = [UIColor whiteColor];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.textAlignment = UITextAlignmentCenter;
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAlertWithTextField:)];
    [textField addGestureRecognizer:tapGestureRecognizer];
    [self.view addSubview:textField];
}

-(void)showAlertWithTextField:(UITapGestureRecognizer *)gesture{
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
    [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [dialog show]; 
}

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:

-(void)addTextFieldToView{
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 31)];
    textField.backgroundColor = [UIColor whiteColor];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.textAlignment = UITextAlignmentCenter;
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAlertWithTextField:)];
    [textField addGestureRecognizer:tapGestureRecognizer];
    [self.view addSubview:textField];
}

-(void)showAlertWithTextField:(UITapGestureRecognizer *)gesture{
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
    [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [dialog show]; 
}
ゞ花落谁相伴 2025-01-02 13:16:39

尝试下面的代码:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Your name?"
                                                  message:nil
                                                 delegate:nil 
                                        cancelButtonTitle:@"Cancel" 
                                        otherButtonTitles:@"OK", nil];

[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message show];

适用于 iOS5

Try below code:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Your name?"
                                                  message:nil
                                                 delegate:nil 
                                        cancelButtonTitle:@"Cancel" 
                                        otherButtonTitles:@"OK", nil];

[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message show];

Works on iOS5

我早已燃尽 2025-01-02 13:16:39

可能会解决你的问题,因为它解决了我的问题:

[enter resignFirstResponder];

Might fix your problem as it solved mine:

[enter resignFirstResponder];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文