About this class

This class make it easier to use Alert Views with blocks, and make the transition between UIAlertView (iOS < 8.0) to UIAlertController (iOS 8.0+)

This allows you to provide directly the code to execute (as a block) in return to the tap on a button, instead of declaring a delegate and implementing the corresponding methods.

This also has the huge advantage of simplifying the code especially when using multiple UIAlertViews in the same object (as in such case, it is not easy to have a clean code if you share the same delegate)

Note: You may also be interested in OHActionSheet

Usage Example

[OHAlertView showAlertWithTitle:@"Alert Demo"
                        message:@"You like this sample?"
                  buttonHandler:^(OHAlertView* alert, NSInteger buttonIndex)
     NSLog(@"button tapped: %d",buttonIndex);

     if (buttonIndex == alert.cancelButtonIndex) {
     } else {

Compatibility Notes

  • This class uses blocks, which is a feature introduced in iOS 4.0.
  • This class uses ARC.
  • This class internally uses UIAlertView if you are targeting iOS < 8.0, and use UIAlertController if you are targeting iOS8 or above


This code is under MIT License.