【问题标题】:UIAlertView not displaying the keyboardUIAlertView 不显示键盘
【发布时间】:2013-09-22 13:47:28
【问题描述】:

我有 UIAlertView,它在加载视图时显示。

 av = [[UIAlertView alloc]initWithTitle:@"New Password" message:@"please enter a new passward" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"done", nil];

av.alertViewStyle = UIAlertViewStyleSecureTextInput;
[av becomeFirstResponder];   


[av show];

但是 iPad 或模拟器上没有显示键盘?

我也试过了

我刚试过

[av becomeFirstResponder];

还有

 UITextField *text = [alertView textFieldAtIndex:0];

[text becomeFirstResponder];

我刚刚尝试了这段代码,它记录了 textField 是第一响应者,但仍然没有键盘。

if([[av textFieldAtIndex:0] isFirstResponder] == YES){
    NSLog(@"av is the first responder.");
}

【问题讨论】:

标签: iphone objective-c ios


【解决方案1】:

将警报设为第一响应者无济于事。您需要将警报视图中的文本框设置为第一响应者。

编辑:

您可能需要致电reloadInputViews(带或不带s,不记得了)。还要仔细检查您是否没有在任何可能破坏它们的地方更改输入视图。

编辑 2:

您可能希望将警报从 viewDidLoad 移动到 viewDidAppear。我已经看到过早更新/呈现 UI 元素的问题。我认为这是其中一种情况。

【讨论】:

  • 编辑 2 帮助了我。我的父视图是动画的,它在实际出现之前加载,因此导致键盘出现不一致。 ViewDidAppear 修复了这个问题。
  • 在模态视图控制器的解除完成之前,我正在显示我的 alertView。将 [alertView show] 移至完成块;希望这对某人有所帮助。
【解决方案2】:

使用

  av = [[UIAlertView alloc]initWithTitle:@"New Password" message:@"please enter a new passward" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"done", nil];
 av.tag=1;
 av.alertViewStyle = UIAlertViewStyleSecureTextInput;

  [av show];

并使用此方法。

 - (void)alertView:(UIAlertView *)alertViews clickedButtonAtIndex:(NSInteger)buttonIndex
 { 
  if (alertViews.tag==1)
 {
    [textfieldname becomeFirstResponder];
  }
}

【讨论】:

  • 这个方法我试过了,还是没有键盘。真的很奇怪!
【解决方案3】:

这行得通

 self.alertView = [[UIAlertView alloc]initWithTitle:@"Login" message:@"Please enter you mobile number" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
    self.alertView.alertViewStyle=UIAlertViewStylePlainTextInput;
        [alertView show];

但不是这个

UIAlertView* alertView = [[UIAlertView alloc] init];
[alertView initWithTitle:...]

【讨论】:

    【解决方案4】:
     av = [[UIAlertView alloc]initWithTitle:@"New Password" message:@"please enter a new passward" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"done", nil];
    
    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
    
    CGAffineTransform Transform = CGAffineTransformMakeTranslation(0, 60);
    
    [tf setBackgroundColor:[UIColor whiteColor]];
    
    [av setTransform:Transform];
    
    [av addSubview:tf];
    
    [av show];
    

    这可行,但您应该能够在 IOS 5 中使用 UIAlertViewStyleSecureTextInput 执行此操作??

    【讨论】:

      【解决方案5】:

      我遇到了同样的问题,但我的解决方案看起来可能不适用于原始海报...

      我有这个代码:

      UIAlertView* alert = [[UIAlertView alloc] init];
      [alert initWithTitle:...]
      

      运行时,没有出现键盘。

      我把它改成了这个,现在键盘出现了:

      UIAlertView* alert = [[UIAlertView alloc] initWithTitle:...];
      

      在创建警报后执行初始化似乎将对象的内部状态保留为“此对象不需要键盘!”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-03
        • 2019-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多