Declared in UIAlertView+BlocksKit.h

Overview

UIAlertView without delegates!

This set of extensions and convenience classes allows for an instance of UIAlertView without the implementation of a delegate. Any time you instantiate a UIAlertView using the methods here, you must add buttons using addButtonWithTitle:handler:otherwise nothing will happen.

A typical invocation will go like this: UIAlertView *testView = [UIAlertView alertViewWithTitle:@“Application Alert” message:@“This app will explode in 42 seconds.”]; [testView setCancelButtonWithTitle:@“Oh No!” handler:^{ NSLog(@“Boom!”); }]; [testView show];

A more traditional, and more useful, modal dialog looks like so: UIAlertView *testView = [UIAlertView alertViewWithTitle:@“Very important!” message:@“Do you like chocolate?”]; [testView addButtonWithTitle:@“Yes” handler:^{ NSLog(@“Yay!”); }]; [testView addButtonWithTitle:@“No” handler:^{ NSLog(@“We hate you.”); }]; [testView show];

Includes code by the following:

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

Tasks

Creating alert views

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.

Contrary to setCancelButtonWithTitle:handler:, you can set this property multiple times but multiple cancel buttons will not be generated.

Declared In

UIAlertView+BlocksKit.h

bk_didDismissBlock

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

The block to be fired after the alert view dismisses.

Declared In

UIAlertView+BlocksKit.h

bk_didShowBlock

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

The block to be fired when the alert view shows.

Declared In

UIAlertView+BlocksKit.h

bk_shouldEnableFirstOtherButtonBlock

@property (nonatomic, copy, setter=bk_SetShouldEnableFirstOtherButtonBlock:) BOOL ( ^ ) ( UIAlertView *alertView ) ( 5 _0 ) bk_shouldEnableFirstOtherButtonBlock
Discussion

The block to be fired to determine whether the first non-cancel should be enabled

Declared In

UIAlertView+BlocksKit.h

bk_willDismissBlock

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

The block to be fired before the alert view will dismiss.

Declared In

UIAlertView+BlocksKit.h

bk_willShowBlock

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

The block to be fired before the alert view will show.

Declared In

UIAlertView+BlocksKit.h

Class Methods

bk_alertViewWithTitle:

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

Creates and returns a new alert view with only a title and cancel button.

Parameters

title

The title of the alert view.

Return Value

A newly created alert view.

Declared In

UIAlertView+BlocksKit.h

bk_alertViewWithTitle:message:

+ (id)bk_alertViewWithTitle:(NSString *)title message:(NSString *)message
Discussion

Creates and returns a new alert view with only a title, message, and cancel button.

Parameters

title

The title of the alert view.

message

The message content of the alert.

Return Value

A newly created alert view.

Declared In

UIAlertView+BlocksKit.h

bk_showAlertViewWithTitle:message:cancelButtonTitle:otherButtonTitles:handler:

+ (UIAlertView *)bk_showAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles handler:(void ( ^ ) ( UIAlertView *alertView , NSInteger buttonIndex ))block
Discussion

Creates and shows a new alert view with only a title, message, and cancel button.

Parameters

title

The title of the alert view.

message

The message content of the alert.

cancelButtonTitle

The title of the cancel button. If both cancelButtonTitle and otherButtonTitles are empty or nil, defaults to a

otherButtonTitles

Titles of additional buttons to add to the receiver.

block

A block of code to be fired on the dismissal of the alert view.

Return Value

The UIAlertView.

Declared In

UIAlertView+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

UIAlertView+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 the button already added to the alert view.

Return Value

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

Declared In

UIAlertView+BlocksKit.h

bk_initWithTitle:message:

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

Returns a configured alert view with only a title, message, and cancel button.

Parameters

title

The title of the alert view.

message

The message content of the alert.

Return Value

An instantiated alert view.

Declared In

UIAlertView+BlocksKit.h

bk_setCancelButtonWithTitle:handler:

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

Set the title and trigger of the cancel button.

Parameters

title

The text of the button.

block

A block of code.

Declared In

UIAlertView+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

UIAlertView+BlocksKit.h