Unable to add UITextField to UIAlertView on iOS7...works in iOS 6
You can't easily alter the view hierarchy of a UIAlertView in iOS 7. (Nor should you; the documentation specifically tells you not to.) Head over to the developer forums to see a long discussion about it.
One alternative in your case is to set alert.alertViewStyle = UIAlertViewStylePlainTextInput;
This will add a text field for you. You can access it in the UIAlertView delegate callback by using UITextField *textField = [alertView textFieldAtIndex:0];
.
@Aaron Brager had the right solution. Additionally I added a line after his suggestion to default a Numeric Keypad.
UIAlertView* dialog = [[UIAlertView alloc] init];[dialog setDelegate:self];[dialog setTitle:@"Enter ESC Score"];[dialog setMessage:@" "];[dialog addButtonWithTitle:@"Cancel"];[dialog addButtonWithTitle:@"OK"];dialog.tag = 5;dialog.alertViewStyle = UIAlertViewStylePlainTextInput;[dialog textFieldAtIndex:0].keyboardType = UIKeyboardTypeNumberPad;CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 0.0);[dialog setTransform: moveUp];[dialog show];[dialog release];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Credit Card Number" message:@"Please enter your credit card number:" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput]; /* Display a numerical keypad for this text field */ UITextField *textField = [alertView textFieldAtIndex:0]; textField.keyboardType = UIKeyboardTypeNumberPad;[alertView show];