ios - 除非重新打开应用程序,否则不会显示 UIAlertView 键盘

标签 ios ios5 uialertview

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

-(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];
    }
}

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

点击主页按钮,然后再次将应用程序带回前台,屏幕上出现相同的警告,但这次实际显示的是键盘。

我该怎么做才能确保键盘在第一时间显示出来?

最佳答案

这是一个奇怪的行为,你为什么不尝试在下一个运行循环中显示警报

[self.emailPromptAlert performSelector:@selector(show) withObject:nil afterDelay:0];

关于ios - 除非重新打开应用程序,否则不会显示 UIAlertView 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11563461/

相关文章:

ios - 为什么不能设置 cell.selectionStyle = UITableViewCellSelectionStyleBlue?

iphone - 在 iOS 中使用电子邮件 uri 方案的附件

iphone - 拉伸(stretch) UIImage 同时保留角点

objective-c - 子类化 UIAlertView

iOS10 WKWebview - evaluateJavaScript ("document.height") 返回 nil

ios - 是否有任何可用于星级评定的控件?

iphone - 返回键的 Unichar 数字?

ios4 - ios 5 后台管理与 ios 4 不同?

ios - 自定义 UIAlertView 在第一次出现后不调整键盘大小

ios - 通过点击外部关闭 UIAlertViewController