diff --git a/Sources/CCAlertView.h b/Sources/CCAlertView.h index d0bdac0..0fe7f69 100644 --- a/Sources/CCAlertView.h +++ b/Sources/CCAlertView.h @@ -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; diff --git a/Sources/CCAlertView.m b/Sources/CCAlertView.m index a44e507..5bf3444 100644 --- a/Sources/CCAlertView.m +++ b/Sources/CCAlertView.m @@ -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]; @@ -78,4 +89,16 @@ - (void) setAlertViewStyle: (UIAlertViewStyle) alertViewStyle } } +- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView +{ + if (self.shouldEnableFirstOtherButtonBlock) + { + return self.shouldEnableFirstOtherButtonBlock(); + } + else + { + return YES; + } +} + @end