-
Notifications
You must be signed in to change notification settings - Fork 1
/
ISBlockAlertView.m
62 lines (51 loc) · 1.5 KB
/
ISBlockAlertView.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// ISBlockAlertView.m
//
// Created by Jimmy on 4/1/12.
// Copyright (c) 2012 Intsig Information Co., LTD. All rights reserved.
#import "ISBlockAlertView.h"
@interface ISBlockAlertView () <UIAlertViewDelegate>
{
}
@property (nonatomic) NSInteger customFirstOtherButtonIndex;
@end
@implementation ISBlockAlertView
- (id) initWithTitle: (NSString*)title
message: (NSString *)message
cancelButtonTitle: (NSString *)cancelButtonTitle
cancelBlock: (void (^)(void)) cancelBlock
otherButtonTitles: (NSArray*)otherButtonTitles
otherButtonBlock: (void (^)(NSInteger index)) otherButtonBlock
{
self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];
if (self) {
_cancelBlock = cancelBlock;
_otherButtonBlock = otherButtonBlock;
_customFirstOtherButtonIndex = cancelButtonTitle?1:0;
for (NSString *title in otherButtonTitles)
{
[self addButtonWithTitle:title];
}
}
return self;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == self.cancelButtonIndex)
{
if (_cancelBlock)
{
_cancelBlock();
}
}
else
{
int index = buttonIndex-[(ISBlockAlertView*)alertView customFirstOtherButtonIndex];
if (_otherButtonBlock)
{
_otherButtonBlock(index);
}
}
}
@end