2011-11-25 117 views
0

我有加载视图时显示的UIAlertView。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]; 

我只是想这段代码,并将其记录的文本框是第一个响应,但仍没有键盘。

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

适用于iOS5的很好.. – beryllium

+0

我使用的是iOS 5这就是为什么它的这样一个奇怪的错误。伊夫使用alertView之前,从来没有 – geminiCoder

+0

@geminiCoder检查此链接它会帮助你http://stackoverflow.com/questions/3346023/resignfirstresponder-doesnt-dismiss-the-keyboard-iphone – Harish

回答

3

使警报进入第一响应者不会有帮助。您需要将警报视图内的te文本框放入第一个响应者。

编辑:

您可能需要调用reloadInputViews(带或不带S,不记得了)。同时仔细检查一下,你是不是在任何可能破坏它们的地方改变输入视图。

编辑2:

你可能希望将提醒从viewDidLoad中进入viewDidAppear。我发现UI元素更新/呈现的问题太早。我认为这是其中的一种情况。

+0

编辑2帮助了我。我的父视图是动画的,它在实际出现之前加载,所以导致出现键盘不一致。 ViewDidAppear解决了这个问题。 – Warr1ck

+0

在解除模态视图控制器完成之前,我显示了我的alertView。将[alertView show]移至完成块;希望这可以帮助某人。 – pnizzle

1

要使用

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]; 
    } 
} 
+0

我试过这种方法,仍然没有键盘。真奇怪!! – geminiCoder

0
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]; 

这工作,但你应该能够使用UIAlertViewStyleSecureTextInput为此在IOS 5?

0

我有同样的问题,但我的解决方案看起来似乎并不适用于原来的海报......

我有这个代码:

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

中运行时,没有键盘出现。

我改成了这一点,并且键盘现在看来:

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

做初始化创建警报后,似乎离开物体的内部状态为“此对象不需要键盘!“

1

这个作品

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:...]