Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 304452b

Browse files
committed
Fix action sheet delegate on iPad running iOS 8 GM
1 parent 3067f0e commit 304452b

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

BlocksKit/UIKit/UIActionSheet+BlocksKit.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
@interface A2DynamicUIActionSheetDelegate : A2DynamicDelegate <UIActionSheetDelegate>
1313

14+
@property (nonatomic, assign) BOOL didHandleButtonClick;
15+
1416
@end
1517

1618
@implementation A2DynamicUIActionSheetDelegate
@@ -22,7 +24,18 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
2224
[realDelegate actionSheet:actionSheet clickedButtonAtIndex:buttonIndex];
2325

2426
void (^block)(void) = self.handlers[@(buttonIndex)];
25-
if (block) block();
27+
28+
// Note: On iPad with iOS 8 GM seed, `actionSheet:clickedButtonAtIndex:` always gets called twice if you tap any button other than Cancel;
29+
// In other words, assume you have two buttons: OK and Cancel; if you tap OK, this method will be called once for the OK button and once
30+
// for the Cancel button. This could result in some really obscure bugs, so adding `didHandleButtonClick` property maintains iOS 7 compatibility.
31+
if (block && self.didHandleButtonClick == NO) {
32+
self.didHandleButtonClick = YES;
33+
34+
// Presenting view controllers from within action sheet delegate does not work on iPad running iOS 8 GM seed, without delay
35+
dispatch_async(dispatch_get_main_queue(), ^{
36+
block();
37+
});
38+
}
2639
}
2740

2841
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet

0 commit comments

Comments
 (0)