Skip to content

Addition for UIActionSheet and UIAlertView to support a block instead of a delegate to check which button was tapped

License

Notifications You must be signed in to change notification settings

gekitz/GKBlocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GKBlocks

Addition for UIActionSheet and UIAlertView to support a block instead of a delegate to check which button was tapped

Install

pod 'GKBlocks'

or you can use the subspecs to install it:

pod 'GKBlocks/UIActionSheet'
pod 'GKBlocks/UIAlertView'

Usage

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];

Author

Georg Kitz, @gekitz

About

Addition for UIActionSheet and UIAlertView to support a block instead of a delegate to check which button was tapped

Resources

License

Stars

Watchers

Forks

Packages

No packages published