Created
March 12, 2015 14:34
-
-
Save dombarnes/13a80063623a8f258f45 to your computer and use it in GitHub Desktop.
iOS7/8 UIAlert
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
{ | |
if (([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedAscending)) { | |
// use UIAlertView | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Are you sure you want to do this on iOS7?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; | |
[alert show]; | |
} | |
else { | |
// use UIAlertController | |
UIAlertController *discardController = [UIAlertController | |
alertControllerWithTitle:@"Alert Title" | |
message:@"This is your alert message" | |
preferredStyle:UIAlertControllerStyleAlert]; | |
UIAlertAction *cancelAction = [UIAlertAction | |
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") | |
style:UIAlertActionStyleCancel | |
handler:^(UIAlertAction *action) | |
{ | |
NSLog(@"Cancel action"); | |
}]; | |
UIAlertAction *discardAction = [UIAlertAction | |
actionWithTitle:@"Discard" | |
style:UIAlertActionStyleDestructive | |
handler:^(UIAlertAction *action) | |
{ | |
NSLog(@"Discard action"); | |
}]; | |
[discardController addAction:cancelAction]; | |
[discardController addAction:discardAction]; | |
[self presentViewController:discardController animated:YES completion:nil]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment