Conforms to UIActionSheetDelegate
Declared in UIActionSheet+BlocksKit.h

Overview

UIActionSheet without delegates!

This set of extensions and convenience classes allows for an instance of UIActionSheet without the implementation of a delegate. Any time you instantiate a UIActionSheet using the methods here, you must add buttons using addButtonWithTitle:handler: to make sure nothing breaks.

A typical invocation might go like this: UIActionSheet *testSheet = [UIActionSheet actionSheetWithTitle:@“Please select one.”]; [testSheet addButtonWithTitle:@“Zip” handler:^{ NSLog(@“Zip!”); }]; [testSheet addButtonWithTitle:@“Zap” handler:^{ NSLog(@“Zap!”); }]; [testSheet addButtonWithTitle:@“Zop” handler:^{ NSLog(@“Zop!”); }]; [testSheet setDestructiveButtonWithTitle:@“No!” handler:^{ NSLog(@“Fine!”); }]; [testSheet setCancelButtonWithTitle:nil handler:^{ NSLog(@“Never mind, then!”); }]; [testSheet showInView:self.view];

Includes code by the following:

Warning: UIActionSheet is only available on a platform with UIKit.

Tasks

Creating action sheets

Adding buttons

Altering actions

Properties

bk_cancelBlock

@property (nonatomic, copy, setter=bk_setCancelBlock:) void ( ^ ) ( void ) bk_cancelBlock
Discussion

The block to be fired when the action sheet is dismissed with the cancel button and/or action.

This property performs the same action as setCancelButtonWithTitle:handler: but with title set to nil. Contrary to setCancelButtonWithTitle:handler:, you can set this property multiple times and multiple cancel buttons will not be generated.

Declared In

UIActionSheet+BlocksKit.h

bk_didDismissBlock

@property (nonatomic, copy, setter=bk_setDidDismissBlock:) void ( ^ ) ( UIActionSheet *actionSheet , NSInteger buttonIndex ) bk_didDismissBlock
Discussion

The block to be fired after the action sheet dismisses.

Declared In

UIActionSheet+BlocksKit.h

bk_didShowBlock

@property (nonatomic, copy, setter=bk_setDidShowBlock:) void ( ^ ) ( UIActionSheet *actionSheet ) bk_didShowBlock
Discussion

The block to be fired when the action sheet shows.

Declared In

UIActionSheet+BlocksKit.h

bk_willDismissBlock

@property (nonatomic, copy, setter=bk_setWillDismissBlock:) void ( ^ ) ( UIActionSheet *actionSheet , NSInteger buttonIndex ) bk_willDismissBlock
Discussion

The block to be fired before the action sheet will dismiss.

Declared In

UIActionSheet+BlocksKit.h

bk_willShowBlock

@property (nonatomic, copy, setter=bk_setWillShowBlock:) void ( ^ ) ( UIActionSheet *actionSheet ) bk_willShowBlock
Discussion

The block to be fired before the action sheet will show.

Declared In

UIActionSheet+BlocksKit.h

Class Methods

bk_actionSheetWithTitle:

+ (id)bk_actionSheetWithTitle:(NSString *)title
Discussion

Creates and returns a new action sheet with only a title and cancel button.

Parameters

title

The header of the action sheet.

Return Value

A newly created action sheet.

Declared In

UIActionSheet+BlocksKit.h

Instance Methods

bk_addButtonWithTitle:handler:

- (NSInteger)bk_addButtonWithTitle:(NSString *)title handler:(void ( ^ ) ( void ))block
Discussion

Add a new button with an associated code block.

Parameters

title

The text of the button.

block

A block of code.

Declared In

UIActionSheet+BlocksKit.h

bk_handlerForButtonAtIndex:

- (void ( ^ ) ( void ))bk_handlerForButtonAtIndex:(NSInteger)index
Discussion

The block that is to be fired when a button is pressed.

Parameters

index

The index of a button already added to the action sheet.

Return Value

A code block, or nil if no block is assigned.

Declared In

UIActionSheet+BlocksKit.h

bk_initWithTitle:

- (id)bk_initWithTitle:(NSString *)title
Discussion

Returns a configured action sheet with only a title and cancel button.

Parameters

title

The header of the action sheet.

Return Value

An instantiated actionSheet.

Declared In

UIActionSheet+BlocksKit.h

bk_setCancelButtonWithTitle:handler:

- (NSInteger)bk_setCancelButtonWithTitle:(NSString *)title handler:(void ( ^ ) ( void ))block
Discussion

Set the title and trigger of the cancel button.

block can be set to nil, but this is generally useless as the cancel button is configured already to do nothing.

iPhone users will have the button shown regardless; if the title is set to nil, it will automatically be localized.

Parameters

title

The text of the button.

block

A block of code.

Declared In

UIActionSheet+BlocksKit.h

bk_setDestructiveButtonWithTitle:handler:

- (NSInteger)bk_setDestructiveButtonWithTitle:(NSString *)title handler:(void ( ^ ) ( void ))block
Discussion

Set the destructive (red) button with an associated code block.

Warning: Because buttons cannot be removed from an action sheet, be aware that the effects of calling this method are cumulative. Previously added destructive buttons will become normal buttons.

Parameters

title

The text of the button.

block

A block of code.

Declared In

UIActionSheet+BlocksKit.h

bk_setHandler:forButtonAtIndex:

- (void)bk_setHandler:(void ( ^ ) ( void ))block forButtonAtIndex:(NSInteger)index
Discussion

Sets the block that is to be fired when a button is pressed.

Parameters

block

A code block, or nil to set no response.

index

The index of a button already added to the action sheet.

Declared In

UIActionSheet+BlocksKit.h