Since I created the block version of UIAlertView and UIActionSheet , I personally never again use the delegated version of Apple.
You can download OHActionSheet and OHAlertView in my GitHub repository .
Since they are based on the Block completion pattern, they are more readable (all code is in one place, there is no common delegate for several UIActionSheets , ...) and more powerful (since blocks also fix their context as needed).
NSArray* otherButtons = @[ @"aaa", @"bbb", @"ccc", @"ddd" ]; [OHActionSheet showSheetInView:self.view title:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:@"erase" otherButtonTitles:otherButtons completion:^(OHActionSheet* sheet, NSInteger buttonIndex) { if (buttonIndex == sheet.cancelButtonIndex) { // cancel } else if (buttonIndex == sheet.destructiveButtonIndex) { // erase } else { NSUInteger idx = buttonIndex - sheet.firstOtherButtonIndex; // Some magic here: thanks to the blocks capturing capability, // the "otherButtons" array is accessible in the completion block! NSString* buttonName = otherButtons[idx]; // Do whatever you want with idx and buttonName } }];
Additional note: like switch/case on NSStrings
Note that in the otherButtons part of the if/else test in your completion handler, you can either test idx using switch/case or use the ObjcSwitch category , which allows you to write switch/case code, but for NSStrings , so you can have such code in its OHActionSheet completion handler:
NSUInteger idx = buttonIndex - sheet.firstOtherButtonIndex; NSString* buttonName = otherButtons[idx]; [buttonName switchCase: @"aaa", ^{ }, @"bbb", ^{ }, @"ccc", ^{ }, ..., nil ];
EDIT: Now that the latest LLVM compiler supports the new Object Literals syntax, you can do the same as ObjcSwitch using the compact NSDictionary syntax:
((dispatch_block_t)@{ @"aaa": ^{ /* Some code here to execute for the "aaa" button */ }, @"bbb": ^{ /* Some code here to execute for the "bbb" button */ }, @"ccc": ^{ /* Some code here to execute for the "ccc" button */ }, }[buttonName] ?:^{ /* Some code here to execute for defaults if no case found above */ })();