Create the alertView with style UIAlertViewStylePlainTextInput:
1 2 3 4 5 6 |
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!" message:@"Please enter your name:" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; UITextField * alertTextField = [alert textFieldAtIndex:0]; alertTextField.keyboardType = UIKeyboardTypeNumberPad; alertTextField.placeholder = @"Enter your name"; [alert show]; |
This produces an alertView:
When pressing any buttons, the regular delegate methods will be called and you can extract the textInput there like so:
1 2 3 |
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"Entered: %@",[[alertView textFieldAtIndex:0] text]); } |