File tree 2 files changed +14
-6
lines changed 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,12 @@ + (void)showAlertWithTitle:(NSString *)title
35
35
36
36
void (^alertActionHandler)(UIAlertAction *) = [^(UIAlertAction *action){
37
37
// This block intentionally retains alertController, and releases it afterwards.
38
- NSUInteger index = [alertController.actions indexOfObject: action];
39
- completion (index - 1 );
38
+ if (action.style == UIAlertActionStyleCancel) {
39
+ completion (NSNotFound );
40
+ } else {
41
+ NSUInteger index = [alertController.actions indexOfObject: action];
42
+ completion (index - 1 );
43
+ }
40
44
alertController = nil ;
41
45
} copy];
42
46
@@ -85,7 +89,11 @@ + (void)showAlertWithTitle:(NSString *)title
85
89
86
90
- (void )alertView : (UIAlertView *)alertView clickedButtonAtIndex : (NSInteger )buttonIndex {
87
91
if (self.completion ) {
88
- self.completion (buttonIndex - alertView.firstOtherButtonIndex );
92
+ if (buttonIndex == alertView.cancelButtonIndex ) {
93
+ self.completion (NSNotFound );
94
+ } else {
95
+ self.completion (buttonIndex - 1 );
96
+ }
89
97
}
90
98
}
91
99
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ - (void)testShowAlertWithAlertViewController {
102
102
cancelButtonTitle: @" Cancel"
103
103
otherButtonTitles: @[ @" Yes" , @" No" ]
104
104
completion: ^(NSUInteger selectedOtherButtonIndex) {
105
- XCTAssertEqual (selectedOtherButtonIndex, - 1 );
105
+ XCTAssertEqual (selectedOtherButtonIndex, NSNotFound );
106
106
107
107
[expectation fulfill ];
108
108
}];
@@ -147,15 +147,15 @@ - (void)testShowWithoutAlertViewController {
147
147
[delegate alertView: self clickedButtonAtIndex: 0 ];
148
148
});
149
149
150
- OCMStub ([mockedAlertView firstOtherButtonIndex ]).andReturn (1 );
150
+ OCMStub ([mockedAlertView cancelButtonIndex ]).andReturn (0 );
151
151
152
152
XCTestExpectation *expectation = [self currentSelectorTestExpectation ];
153
153
[PFAlertView showAlertWithTitle: @" Title"
154
154
message: @" Message"
155
155
cancelButtonTitle: @" Cancel"
156
156
otherButtonTitles: @[ @" Yes" , @" No" ]
157
157
completion: ^(NSUInteger selectedOtherButtonIndex) {
158
- XCTAssertEqual (selectedOtherButtonIndex, - 1 );
158
+ XCTAssertEqual (selectedOtherButtonIndex, NSNotFound );
159
159
160
160
[expectation fulfill ];
161
161
}];
You can’t perform that action at this time.
0 commit comments