Last active
June 20, 2016 20:23
-
-
Save olxios/b5b0b65d49d8b8a1015ce2feb2eb907e to your computer and use it in GitHub Desktop.
Testing UIAlertController: http://swiftiostutorials.com/using-uialertcontroller-instead-good-old-uialertview/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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