Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Block-using subclasses of UIActionSheet and UIAlertView
Branch: master

public domain

latest commit 7350e0ca17
Rob Mayoff authored
Failed to load latest commit information.
BlockModals public domain
TestBlockModals.xcodeproj public domain
TestBlockModals public domain
UnitTests public domain
.gitignore import stub project
COPYRIGHT public domain public domain


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

Something went wrong with that request. Please try again.