Addition for UIActionSheet and UIAlertView to support a block instead of a delegate to check which button was tapped
pod 'GKBlocks'
or you can use the subspecs to install it:
pod 'GKBlocks/UIActionSheet'
pod 'GKBlocks/UIAlertView'
UIActionSheet and UIAlertView are extended with 2 init methods which support a block as parameter. For UIActionSheet:
GKActionSheetBlock block = ^(UIActionSheet *sheet, NSInteger buttonIndex) {
NSLog(@"CancelButton Pressed = %d", sheet.cancelButtonIndex == buttonIndex);
};
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Test" block:block cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"OK", nil];
[sheet showInView:self.view];
For UIAlertView:
GKAlertViewBlock block = ^(UIAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"CancelButton Pressed = %d", alertView.cancelButtonIndex == buttonIndex);
};
[[[UIAlertView alloc] initWithTitle:@"Test" message:@"This is a test" block:block cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] show];
Georg Kitz, @gekitz