Created
April 7, 2010 16:50
-
-
Save jdewind/359120 to your computer and use it in GitHub Desktop.
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)show:(NSString *)message confirmed:(ConfirmationBlock)confirmBlock canceled:(ConfirmationBlock)canceledBlock { | |
if(blocks == nil) { | |
blocks = [[NSMutableDictionary dictionary] retain]; | |
delegate = [[BlockConfirmationAlert alloc] init]; | |
} | |
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Confirm" message:message delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil] autorelease]; | |
NSDictionary *blockDict = [NSDictionary dictionaryWithObjectsAndKeys:[[confirmBlock copy] autorelease], @"confirm", [[canceledBlock copy] autorelease], @"cancel", nil]; | |
[blocks setObject:blockDict forKey:[NSNumber numberWithUnsignedInt:[alertView hash]]]; | |
[alertView show]; | |
} | |
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { | |
NSNumber *key = [NSNumber numberWithUnsignedInt:[alertView hash]]; | |
NSDictionary *blockDict = [blocks objectForKey:key]; | |
if (alertView.cancelButtonIndex == buttonIndex) { | |
((ConfirmationBlock)[blockDict objectForKey:@"cancel"])(alertView); | |
} else { | |
((ConfirmationBlock)[blockDict objectForKey:@"confirm"])(alertView); | |
} | |
[blocks removeObjectForKey:key]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment