Skip to content

Instantly share code, notes, and snippets.

@olxios
Last active June 20, 2016 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olxios/b5b0b65d49d8b8a1015ce2feb2eb907e to your computer and use it in GitHub Desktop.
Save olxios/b5b0b65d49d8b8a1015ce2feb2eb907e to your computer and use it in GitHub Desktop.
- (void)testAlert1:(id)sender
{
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error!"
message:@"Test error message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"Dismiss button tapped!");
}];
[controller addAction:alertAction];
[self presentViewController:controller animated:YES completion:nil];
}
- (IBAction)testAlert2:(id)sender
{
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error!"
message:@"Test error message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"Dismiss button tapped!");
}];
[controller addAction:alertAction];
UIAlertAction *first = [UIAlertAction actionWithTitle:@"1" style:UIAlertActionStyleDefault handler:nil];
[controller addAction:first];
UIAlertAction *second = [UIAlertAction actionWithTitle:@"2" style:UIAlertActionStyleDefault handler:nil];
[controller addAction:second];
UIAlertAction *third = [UIAlertAction actionWithTitle:@"3" style:UIAlertActionStyleDefault handler:nil];
[controller addAction:third];
UIAlertAction *last = [UIAlertAction actionWithTitle:@"4" style:UIAlertActionStyleCancel handler:nil];
[controller addAction:last];
[self presentViewController:controller animated:YES completion:nil];
}
- (IBAction)testMultipleCancels:(id)sender
{
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error!"
message:@"Test multiple cancels"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstCancelAction = [UIAlertAction actionWithTitle:@"Cancel 1"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"Cancel 1 button tapped!");
}];
[controller addAction:firstCancelAction];
UIAlertAction *secondCancelAction = [UIAlertAction actionWithTitle:@"Cancel 2"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"Cancel 2 button tapped!");
}];
[controller addAction:secondCancelAction];
[self presentViewController:controller animated:YES completion:nil];
}
- (IBAction)testTextField:(id)sender
{
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Error!"
message:@"Test error message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
NSLog(@"Dismiss button tapped!");
NSLog(@"Textfield text - %@", controller.textFields.firstObject.text);
}];
[controller addAction:alertAction];
[controller addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Test";
textField.textColor = [UIColor redColor];
}];
[self presentViewController:controller animated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment