-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockAlertView.m
executable file
·39 lines (27 loc) · 1.12 KB
/
BlockAlertView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "BlockAlertView.h"
@interface BlockAlertView () <UIAlertViewDelegate>
@property (nonatomic, strong) NSMutableArray *blocksArray;
@end
#pragma mark - Implementation
@implementation BlockAlertView
@synthesize blocksArray;
- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButton cancelBlock:(void (^)(void))cancelBlock {
self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButton otherButtonTitles:nil];
if (self) {
self.blocksArray = [NSMutableArray array];
if (!cancelBlock) cancelBlock = ^{};
[self.blocksArray addObject:[cancelBlock copy]];
}
return self;
}
- (void)addButtonWithTitle:(NSString *)title selectionBlock:(void (^)(void))selectionBlock {
[super addButtonWithTitle:title];
[self.blocksArray addObject:[selectionBlock copy]];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex >= 0 && buttonIndex < blocksArray.count) {
void(^block)(void) = (self.blocksArray)[buttonIndex];
block();
}
}
@end