0

I have UIAlertView which is being displayed upon the load of a view.

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

However the keyboard is not being display on the iPad or the simulator?

I have also tried

I just tried

[av becomeFirstResponder];

and also

 UITextField *text = [alertView textFieldAtIndex:0];

[text becomeFirstResponder];

I just tried this piece of code and it logs that the textField is the first responder but still no keyboard.

if([[av textFieldAtIndex:0] isFirstResponder] == YES){
    NSLog(@"av is the first responder.");
}
geminiCoder
  • 2,918
  • 2
  • 29
  • 50
  • I'm using iOS 5 thats why its such a weird bug. Ive used alertView before and never had a problem with it. – geminiCoder Nov 25 '11 at 11:13
  • @geminiCoder check this link it will help you http://stackoverflow.com/questions/3346023/resignfirstresponder-doesnt-dismiss-the-keyboard-iphone – Harish Nov 25 '11 at 11:22
  • See this: http://stackoverflow.com/questions/25563108/uialertviews-textfield-does-not-show-keyboard-in-ios8 – cetcet Sep 19 '14 at 22:07

5 Answers5

3

Making the alert into the first responder won't help. You need to make te text box inside the alert view into the first responder.

Edit:

You may need to call reloadInputViews (with or without the s, don't remember). Also double check that you're not changing the input views anywhere that might be breaking them.

Edit 2:

You might want to move the alert from viewDidLoad into viewDidAppear. I've seen problems with UI elements being updated/presented too early. This is one of those cases, I think.

Moshe
  • 57,511
  • 78
  • 272
  • 425
  • Edit 2 helped me. My parent view was animated and it loaded before it actually appeared, so that was causing an inconsistency in the keyboard appearing. ViewDidAppear fixed this. – Warr1ck Oct 04 '12 at 02:28
  • I was showing my alertView before dismissal of a modal viewController was complete. Moved [alertView show] to the completion block; Hope this helps someone. – pnizzle May 27 '13 at 02:27
1

this works

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

but not this

UIAlertView* alertView = [[UIAlertView alloc] init];
[alertView initWithTitle:...]
Virendra
  • 2,560
  • 3
  • 23
  • 37
UIResponder
  • 785
  • 9
  • 15
1

To use

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

and use this method.

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

I had the same issue, but my solution looks like it might not apply to original poster...

I had this code :

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

When run, no keyboard appeared.

I changed it to this, and keyboard now appears:

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

Doing the init after alert was created seem to leave internal state of object as "this object doesn't need a keyboard!"

Stephan
  • 41,764
  • 65
  • 238
  • 329
Bill P
  • 1
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];

This works but you should be able to do this in IOS 5 using UIAlertViewStyleSecureTextInput??

geminiCoder
  • 2,918
  • 2
  • 29
  • 50