除非重新打开应用程序,否则UIAlertView键盘不会显示 [英] UIAlertView keyboard doesn't get shown unless app is re-opened

查看:91
本文介绍了除非重新打开应用程序,否则UIAlertView键盘不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户打开我的应用程序时,我想检查存储在默认值中的值,如果它不存在则提示用户输入值。存储/读取值似乎正在起作用。

When the user opens my app, I want to check for a value stored in the defaults, and if it is not present prompt the user to input a value. The storing/reading of the value appears to be working.

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"Checking if there is an email address set");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString * emailAddress = [defaults objectForKey:@"emailAddress"];
    if (IsEmpty(emailAddress))
    {
        NSLog(@"email address is blank, prompting user to enter one..");
        self.emailPromptAlert = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                          message:@"Enter Email address:" 
                                                         delegate:self 
                                                cancelButtonTitle:@"Cancel" 
                                                otherButtonTitles:@"OK", nil];
        [self.emailPromptAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
        [self.emailPromptAlert setTag:1];
        [self.emailPromptAlert show];
    }
}

我遇到的问题是我做的时候干净安装我的应用程序并首次加载,警报按预期显示,但没有显示键盘,因此用户实际上无法键入任何内容。

The problem that I have, is when I do a clean install of my app and load for the first time, the alert shows up as expected but there is no keyboard shown, so the user can't actually type anything.

单击主页按钮,然后再次将应用程序带回前台,屏幕上显示相同的提醒,但这次键盘实际显示。

Clicking the home button then bringing the app back into the foreground again, the same alert is on screen but this time the keyboard is actually showing.

我可以做些什么来确保第一次显示键盘?

What can I do to make sure the keyboard gets shown the first time?

推荐答案

我我不完全确定,但也许这可行吗?

I am not totally sure, but maybe this could work?

self.emailPromptAlert = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                      message:@"Enter Email address:" 
                                                     delegate:self 
                                            cancelButtonTitle:@"Cancel" 
                                            otherButtonTitles:@"OK", nil];
[self.emailPromptAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[self.emailPromptAlert setTag:1];

[self.emailPromptAlert show];

//try this?
UITextField *textField = [self.emailPromptAlert textFieldAtIndex:0];
[textField becomeFirstResponder];

这并没有真正解决为什么它没有显示在第一名,但它可能是一个解决方案。

This doesn't really get to the root of the problem of why it isn't showing in the first place, but it could be a solution.

这篇关于除非重新打开应用程序,否则UIAlertView键盘不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆