Skip to content

Instantly share code, notes, and snippets.

@tinkertims
Created June 10, 2016 07:34
Show Gist options
  • Save tinkertims/62907f664126e21ea56d3d05b38199a7 to your computer and use it in GitHub Desktop.
Save tinkertims/62907f664126e21ea56d3d05b38199a7 to your computer and use it in GitHub Desktop.
Alert using UIAlertController (TextField and Two buttons)
// Show a text entry alert with two custom buttons.
- (void)showTextEntryAlert {
NSString *title = NSLocalizedString(@"Short_title", nil);
NSString *message = NSLocalizedString(@"Message", nil);
NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);
NSString *otherButtonTitle = NSLocalizedString(@"OK", nil);
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
// Add the text field for text entry.
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// If you need to customize the text field, you can do so here.
}];
// Create the actions.
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"The \"Text Entry\" alert's cancel action occured.");
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"The \"Text Entry\" alert's other action occured.");
}];
// Add the actions.
[alertController addAction:cancelAction];
[alertController addAction:otherAction];
[self presentViewController:alertController animated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment