Block-using subclasses of UIActionSheet and UIAlertView
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This project lets you set a block as the handler for a button in a UIActionSheet or UIAlertView.


The project defines a subclass of UIAlertView named BlockAlertView. You can use the BlockAlertView anywhere you use a UIAlertView. It supports everything UIAlertView supports; it is a drop-in replacement.

What BlockAlertView adds is a method named addButtonWithTitle:handler: that lets you set a block to be called when the user taps the button. You use it like this:

BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:@"Intruder Alert!"
    message:@"Your vessel has been boarded by hostile aliens."];
alert.cancelButtonIndex = [alert addButtonWithTitle:@"Ignore Them"];

[alert addButtonWithTitle:@"Beg For Mercy" handler:^{
    [self begForMercy];

[alert addButtonWithTitle:@"Blast Them" handler:^{
    [self.phaser setMode:PhaserModeKill];
    [self fireWeapon:self.phaser];

[alert show];

To use BlockAlertView in your own project, just copy the files BlockAlertView.h and BlockAlertView.m to your project, and add BlockAlertView.m to the “Compile Sources” phase of your target.


The BlockActionSheet class is a subclass of UIActionSheet and adds the same methods as BlockAlertView. To use it in your own project, copy BlockActionSheet.h and BlockActionSheet.m to your project, and add BlockActionSheet.m to the “Compile Sources” phase of your target.

The contents of this repository are dedicated to the public domain, in accordance with the CC0 1.0 Universal Public Domain Dedication, which is reproduced in the file COPYRIGHT.

Author: Rob Mayoff 2012-05-16