-
Notifications
You must be signed in to change notification settings - Fork 1
/
ISBlockActionSheet.m
90 lines (78 loc) · 2.26 KB
/
ISBlockActionSheet.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// ISBockActionSheet.m
//
// Created by Jimmy on 4/1/12.
// Copyright (c) 2012 Intsig Information Co., LTD. All rights reserved.
#import "ISBlockActionSheet.h"
@interface ISBlockActionSheet () <UIActionSheetDelegate>
{
}
@property (nonatomic) NSInteger customFirstOtherButtonIndex;
@end
@implementation ISBlockActionSheet
@synthesize customFirstOtherButtonIndex;
- (id) initWithTitle:(NSString *) title
cancelButtonTitle:(NSString *)cancelButtonTitle
cancelBlock:(void (^)(void))cancelBLock
destructiveButtonTitle:(NSString *) destructiveButtonTitle
destructiveBlock:(void (^)(void)) destructiveBlock
otherButtonTitles:(NSArray *) otherButtonTitles
otherButtonBlock:(void (^)(NSInteger index)) otherButtonBlock;
{
self = [super init];
if (self)
{
self.customFirstOtherButtonIndex = 0;
if (destructiveButtonTitle)
{
[self addButtonWithTitle:destructiveButtonTitle];
self.destructiveButtonIndex = 0;
self.customFirstOtherButtonIndex++;
}
for (NSString *title in otherButtonTitles)
{
[self addButtonWithTitle:title];
}
if (cancelButtonTitle)
{
[self addButtonWithTitle:cancelButtonTitle];
self.cancelButtonIndex = self.numberOfButtons - 1;
}
_cancelBlock = cancelBLock;
_destructiveBlock = destructiveBlock;
_otherButtonBlock = otherButtonBlock;
self.delegate = self;
self.title = title;
}
return self;
}
- (void)actionSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
{
if (buttonIndex < 0) {
return;
}
if (buttonIndex == self.cancelButtonIndex)
{
if (_cancelBlock)
{
_cancelBlock();
}
}
else if (buttonIndex == self.destructiveButtonIndex)
{
if (_destructiveBlock)
{
_destructiveBlock();
}
}
else
{
int index = buttonIndex-[(ISBlockActionSheet*)actionSheet customFirstOtherButtonIndex];
if (_otherButtonBlock)
{
_otherButtonBlock(index);
}
}
}
@end