Skip to content
This repository has been archived by the owner on Aug 28, 2018. It is now read-only.

Add support for shouldEnableFirstOtherButton delegate handling #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/CCAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ extern NSString *const CCAlertViewAnimatedKey;

@property(nonatomic, assign) UIAlertViewStyle alertViewStyle;
@property(copy) dispatch_block_t dismissAction;
@property (copy, nonatomic) BOOL (^shouldEnableFirstOtherButtonBlock) (void);

- (id) initWithTitle: (NSString*) title message: (NSString*) message;
- (id) initWithTitle: (NSString*) title message: (NSString*) message cancelButtonTitle:(NSString*)cancelButtonTitle cancelButtonBlock:(dispatch_block_t)cancelButtonBlock firstOtherButtonTitle:(NSString*)firstOtherButtonTitle firstOtherButtonBlock:(dispatch_block_t)firstOtherButtonBlock;
- (void) addButtonWithTitle: (NSString*) title block: (dispatch_block_t) block;

- (void) show;
Expand Down
23 changes: 23 additions & 0 deletions Sources/CCAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ - (id) initWithTitle: (NSString*) title message: (NSString*) message
return self;
}

- (id) initWithTitle: (NSString*) title message: (NSString*) message cancelButtonTitle:(NSString*)cancelButtonTitle cancelButtonBlock:(dispatch_block_t)cancelButtonBlock firstOtherButtonTitle:(NSString*)firstOtherButtonTitle firstOtherButtonBlock:(dispatch_block_t)firstOtherButtonBlock
{
self = [super init];
alert = [[UIAlertView alloc] initWithTitle:title message:message
delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:firstOtherButtonTitle, nil];
if (!cancelButtonBlock) cancelButtonBlock = ^{};
if (!firstOtherButtonBlock) firstOtherButtonBlock = ^{};
blocks = [[NSMutableArray alloc] initWithObjects:[cancelButtonBlock copy], [firstOtherButtonBlock copy], nil];
return self;
}

- (void) show
{
[alert show];
Expand Down Expand Up @@ -78,4 +89,16 @@ - (void) setAlertViewStyle: (UIAlertViewStyle) alertViewStyle
}
}

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
if (self.shouldEnableFirstOtherButtonBlock)
{
return self.shouldEnableFirstOtherButtonBlock();
}
else
{
return YES;
}
}

@end