我有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.");
}
将警报发送到第一响应程序不会有帮助。您需要将警报视图中的文本框设置为第一响应程序。
编辑:
您可能需要调用reloadInputViews
(带或不带s,请不要记住(。还要仔细检查是否没有在任何可能破坏输入视图的地方更改输入视图。
编辑2:
您可能希望将警报从viewDidLoad移动到viewDidPear。我发现UI元素更新/呈现太早的问题。我认为这就是其中一个案例。
使用
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];
}
}
这适用于
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:...]
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];
这是有效的,但你应该能够在IOS5中使用UIAlertViewStyleSecureTextInput??
我也遇到了同样的问题,但我的解决方案看起来可能不适用于原始海报。。。
我有这个代码:
UIAlertView* alert = [[UIAlertView alloc] init];
[alert initWithTitle:...]
运行时,没有出现键盘。
我把它改成了这个,键盘现在出现了:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:...];
在创建警报后进行初始化似乎会将对象的内部状态保留为"此对象不需要键盘!">