Skip to content

Instantly share code, notes, and snippets.

@blixt
Last active August 29, 2015 14:14
Show Gist options
  • Save blixt/52d001ffc9e1069c6d11 to your computer and use it in GitHub Desktop.
Save blixt/52d001ffc9e1069c6d11 to your computer and use it in GitHub Desktop.
- (void)alertWithTitle:(NSString *)title
message:(NSString *)message
close:(NSString *)closeText
action:(NSString *)actionText
then:(void (^)(void))block
{
if ([UIAlertController class]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
if (closeText) {
[alert addAction:[UIAlertAction actionWithTitle:closeText style:UIAlertActionStyleCancel handler:nil]];
}
if (actionText) {
[alert addAction:[UIAlertAction actionWithTitle:closeText style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
if (block) block();
}]];
}
[self presentViewController:alert animated:YES completion:nil];
} else {
AlertViewCallback *callback = nil;
if (block) {
callback = [AlertViewCallback callback:block];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:callback
cancelButtonTitle:closeText
otherButtonTitles:nil];
if (actionText) {
[alert addButtonWithTitle:actionText];
}
[alert show];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment