Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertView: UIAlertViewStyleSecureTextInput: Numeric keyboard

I'm currently using this UIAlertView to do a login popup,

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Restricted"
                                                message:@"Please Enter Code to Enable Fields" 
                                               delegate:self
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"Login"
                      , nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

[alert show];

However I would like the text input to be a numeric keyboard instead of the regular keyboard

Is there a easy way to do this, or do I have to look into creating a custom UIAleartView

like image 513
Jason Rogers Avatar asked May 14 '12 08:05

Jason Rogers


3 Answers

You can try this to change the keyboard type of the UIAlertView's field:

[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
like image 147
Abhishek Singh Avatar answered Oct 30 '22 11:10

Abhishek Singh


Cool answer but for iOS 7 I have a little adaptation

alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] resignFirstResponder];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypePhonePad];
[[alert textFieldAtIndex:0] becomeFirstResponder];
like image 29
Max Tymchii Avatar answered Oct 30 '22 10:10

Max Tymchii


 UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"Enter File Number" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        alertView1.alertViewStyle = UIKeyboardTypePhonePad;
        myTextField = [alertView1 textFieldAtIndex:0];
        myTextField.keyboardType=UIKeyboardTypeNumberPad;
        [alertView1 setTag:3];
        [alertView1 show];
like image 31
Sandy Patel Avatar answered Oct 30 '22 11:10

Sandy Patel