diff --git a/Example/FCAlertView/ExampleViewController.m b/Example/FCAlertView/ExampleViewController.m index d296ceb..1ab2e0b 100644 --- a/Example/FCAlertView/ExampleViewController.m +++ b/Example/FCAlertView/ExampleViewController.m @@ -559,6 +559,8 @@ - (IBAction)showAlert:(id)sender { */ + [alert addButton:@"Block" withActionBlock:nil]; + /* USING BLOCK ACTION FOR DONE BUTTON -- Uncomment to Try it out [alert doneActionBlock:^{ diff --git a/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.h b/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.h index 53b8369..014469f 100644 --- a/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.h +++ b/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.h @@ -77,34 +77,34 @@ typedef void (^FCActionBlock)(void); @property (nonatomic, copy) FCActionBlock actionBlock; @property (nonatomic, copy) FCActionBlock doneBlock; -- (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action; -- (void)doneActionBlock:(FCActionBlock)action; +- (void)addButton:(NSString *)title withActionBlock:(nullable FCActionBlock)action; +- (void)doneActionBlock:(nullable FCActionBlock)action; // Color Schemes -@property (nonatomic, retain) UIColor * colorScheme; -@property (nonatomic, retain) UIColor * titleColor; -@property (nonatomic, retain) UIColor * subTitleColor; +@property (nonatomic, retain) UIColor * __nullable colorScheme; +@property (nonatomic, retain) UIColor * __nullable titleColor; +@property (nonatomic, retain) UIColor * __nullable subTitleColor; // Preset Flat Colors -@property (nonatomic, retain) UIColor * flatTurquoise; -@property (nonatomic, retain) UIColor * flatGreen; -@property (nonatomic, retain) UIColor * flatBlue; -@property (nonatomic, retain) UIColor * flatMidnight; -@property (nonatomic, retain) UIColor * flatPurple; -@property (nonatomic, retain) UIColor * flatOrange; -@property (nonatomic, retain) UIColor * flatRed; -@property (nonatomic, retain) UIColor * flatSilver; -@property (nonatomic, retain) UIColor * flatGray; +@property (nonatomic, retain) UIColor * __nullable flatTurquoise; +@property (nonatomic, retain) UIColor * __nullable flatGreen; +@property (nonatomic, retain) UIColor * __nullable flatBlue; +@property (nonatomic, retain) UIColor * __nullable flatMidnight; +@property (nonatomic, retain) UIColor * __nullable flatPurple; +@property (nonatomic, retain) UIColor * __nullable flatOrange; +@property (nonatomic, retain) UIColor * __nullable flatRed; +@property (nonatomic, retain) UIColor * __nullable flatSilver; +@property (nonatomic, retain) UIColor * __nullable flatGray; @end @protocol FCAlertViewDelegate @optional -- (void)FCAlertView:(FCAlertView *)alertView clickedButtonIndex:(NSInteger)index buttonTitle:(NSString *)title; -- (void)FCAlertViewDismissed:(FCAlertView *)alertView; -- (void)FCAlertViewWillAppear:(FCAlertView *)alertView; -- (void)FCAlertDoneButtonClicked:(FCAlertView *)alertView; +- (void)FCAlertView:( FCAlertView * _Null_unspecified )alertView clickedButtonIndex:(NSInteger)index buttonTitle:(NSString * _Null_unspecified)title; +- (void)FCAlertViewDismissed:(FCAlertView * _Null_unspecified)alertView; +- (void)FCAlertViewWillAppear:(FCAlertView * _Null_unspecified)alertView; +- (void)FCAlertDoneButtonClicked:(FCAlertView * _Null_unspecified)alertView; @end diff --git a/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.m b/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.m index 21ce459..c2384a7 100644 --- a/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.m +++ b/Example/Pods/FCAlertView/FCAlertView/Classes/FCAlertView.m @@ -466,7 +466,7 @@ - (void)drawRect:(CGRect)rect { alertViewVector = [UIButton buttonWithType:UIButtonTypeCustom]; else alertViewVector = [UIButton buttonWithType:UIButtonTypeSystem]; - + alertViewVector.frame = CGRectMake(alertViewContents.frame.size.width/2 - 15.0f, -15.0f, 30.0f, @@ -577,12 +577,12 @@ - (void) showAlertInView:(UIViewController *)view withTitle:(NSString *)title wi if (!alertViewWithVector) vectorImage = image; - + // Checks prior to presenting View [self checkCustomizationValid]; [self safetyCloseCheck]; - + [view.view.window addSubview:self]; } @@ -627,11 +627,18 @@ - (void) dismissAlertView { } +#pragma mark - Action Block Methods + - (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action { - if (alertButtons.count < 2) - [alertButtons addObject:@{@"title" : title, - @"action" : action}]; + if (alertButtons.count < 2) { + if (action != nil) + [alertButtons addObject:@{@"title" : title, + @"action" : action}]; + else + [alertButtons addObject:@{@"title" : title, + @"action" : @0}]; + } _numberOfButtons = alertButtons.count; @@ -639,7 +646,8 @@ - (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action { - (void)doneActionBlock:(FCActionBlock)action { - self.doneBlock = action; + if (action != nil) + self.doneBlock = action; } @@ -647,17 +655,19 @@ - (void)doneActionBlock:(FCActionBlock)action { #pragma mark Button Selection - (void)handleButton:(id)sender { - + id strongDelegate = self.delegate; UIButton *clickedButton = (UIButton*)sender; NSDictionary *btnDict = [alertButtons objectAtIndex:[sender tag]]; - if ([btnDict objectForKey:@"action"] != nil && ![[btnDict objectForKey:@"action"] isEqual:@0]) { - FCActionBlock block = [btnDict objectForKey:@"action"]; - if (block) - block(); + if (btnDict != nil) { + if ([btnDict objectForKey:@"action"] != nil && ![[btnDict objectForKey:@"action"] isEqual:@0]) { + FCActionBlock block = [btnDict objectForKey:@"action"]; + if (block) + block(); + } } if ([strongDelegate respondsToSelector:@selector(FCAlertView:clickedButtonIndex:buttonTitle:)]) { diff --git a/FCAlertView/Classes/FCAlertView.h b/FCAlertView/Classes/FCAlertView.h index 53b8369..014469f 100644 --- a/FCAlertView/Classes/FCAlertView.h +++ b/FCAlertView/Classes/FCAlertView.h @@ -77,34 +77,34 @@ typedef void (^FCActionBlock)(void); @property (nonatomic, copy) FCActionBlock actionBlock; @property (nonatomic, copy) FCActionBlock doneBlock; -- (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action; -- (void)doneActionBlock:(FCActionBlock)action; +- (void)addButton:(NSString *)title withActionBlock:(nullable FCActionBlock)action; +- (void)doneActionBlock:(nullable FCActionBlock)action; // Color Schemes -@property (nonatomic, retain) UIColor * colorScheme; -@property (nonatomic, retain) UIColor * titleColor; -@property (nonatomic, retain) UIColor * subTitleColor; +@property (nonatomic, retain) UIColor * __nullable colorScheme; +@property (nonatomic, retain) UIColor * __nullable titleColor; +@property (nonatomic, retain) UIColor * __nullable subTitleColor; // Preset Flat Colors -@property (nonatomic, retain) UIColor * flatTurquoise; -@property (nonatomic, retain) UIColor * flatGreen; -@property (nonatomic, retain) UIColor * flatBlue; -@property (nonatomic, retain) UIColor * flatMidnight; -@property (nonatomic, retain) UIColor * flatPurple; -@property (nonatomic, retain) UIColor * flatOrange; -@property (nonatomic, retain) UIColor * flatRed; -@property (nonatomic, retain) UIColor * flatSilver; -@property (nonatomic, retain) UIColor * flatGray; +@property (nonatomic, retain) UIColor * __nullable flatTurquoise; +@property (nonatomic, retain) UIColor * __nullable flatGreen; +@property (nonatomic, retain) UIColor * __nullable flatBlue; +@property (nonatomic, retain) UIColor * __nullable flatMidnight; +@property (nonatomic, retain) UIColor * __nullable flatPurple; +@property (nonatomic, retain) UIColor * __nullable flatOrange; +@property (nonatomic, retain) UIColor * __nullable flatRed; +@property (nonatomic, retain) UIColor * __nullable flatSilver; +@property (nonatomic, retain) UIColor * __nullable flatGray; @end @protocol FCAlertViewDelegate @optional -- (void)FCAlertView:(FCAlertView *)alertView clickedButtonIndex:(NSInteger)index buttonTitle:(NSString *)title; -- (void)FCAlertViewDismissed:(FCAlertView *)alertView; -- (void)FCAlertViewWillAppear:(FCAlertView *)alertView; -- (void)FCAlertDoneButtonClicked:(FCAlertView *)alertView; +- (void)FCAlertView:( FCAlertView * _Null_unspecified )alertView clickedButtonIndex:(NSInteger)index buttonTitle:(NSString * _Null_unspecified)title; +- (void)FCAlertViewDismissed:(FCAlertView * _Null_unspecified)alertView; +- (void)FCAlertViewWillAppear:(FCAlertView * _Null_unspecified)alertView; +- (void)FCAlertDoneButtonClicked:(FCAlertView * _Null_unspecified)alertView; @end diff --git a/FCAlertView/Classes/FCAlertView.m b/FCAlertView/Classes/FCAlertView.m index 21ce459..c2384a7 100644 --- a/FCAlertView/Classes/FCAlertView.m +++ b/FCAlertView/Classes/FCAlertView.m @@ -466,7 +466,7 @@ - (void)drawRect:(CGRect)rect { alertViewVector = [UIButton buttonWithType:UIButtonTypeCustom]; else alertViewVector = [UIButton buttonWithType:UIButtonTypeSystem]; - + alertViewVector.frame = CGRectMake(alertViewContents.frame.size.width/2 - 15.0f, -15.0f, 30.0f, @@ -577,12 +577,12 @@ - (void) showAlertInView:(UIViewController *)view withTitle:(NSString *)title wi if (!alertViewWithVector) vectorImage = image; - + // Checks prior to presenting View [self checkCustomizationValid]; [self safetyCloseCheck]; - + [view.view.window addSubview:self]; } @@ -627,11 +627,18 @@ - (void) dismissAlertView { } +#pragma mark - Action Block Methods + - (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action { - if (alertButtons.count < 2) - [alertButtons addObject:@{@"title" : title, - @"action" : action}]; + if (alertButtons.count < 2) { + if (action != nil) + [alertButtons addObject:@{@"title" : title, + @"action" : action}]; + else + [alertButtons addObject:@{@"title" : title, + @"action" : @0}]; + } _numberOfButtons = alertButtons.count; @@ -639,7 +646,8 @@ - (void)addButton:(NSString *)title withActionBlock:(FCActionBlock)action { - (void)doneActionBlock:(FCActionBlock)action { - self.doneBlock = action; + if (action != nil) + self.doneBlock = action; } @@ -647,17 +655,19 @@ - (void)doneActionBlock:(FCActionBlock)action { #pragma mark Button Selection - (void)handleButton:(id)sender { - + id strongDelegate = self.delegate; UIButton *clickedButton = (UIButton*)sender; NSDictionary *btnDict = [alertButtons objectAtIndex:[sender tag]]; - if ([btnDict objectForKey:@"action"] != nil && ![[btnDict objectForKey:@"action"] isEqual:@0]) { - FCActionBlock block = [btnDict objectForKey:@"action"]; - if (block) - block(); + if (btnDict != nil) { + if ([btnDict objectForKey:@"action"] != nil && ![[btnDict objectForKey:@"action"] isEqual:@0]) { + FCActionBlock block = [btnDict objectForKey:@"action"]; + if (block) + block(); + } } if ([strongDelegate respondsToSelector:@selector(FCAlertView:clickedButtonIndex:buttonTitle:)]) {