Created
June 17, 2013 16:02
-
-
Save jdriscoll/5798059 to your computer and use it in GitHub Desktop.
Block-based Action Sheet wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JCDActionSheetDelegate.h | |
// Created by Justin Driscoll on 4/3/13. | |
// | |
#import <UIKit/UIKit.h> | |
typedef void (^JCDActionSheetDelegateCallback)(UIActionSheet *actionSheet, NSInteger buttonIndex); | |
@interface JCDActionSheetDelegate : NSObject <UIActionSheetDelegate> | |
- (id)initWithCallback:(JCDActionSheetDelegateCallback)callback; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JCDActionSheetDelegate.m | |
// Created by Justin Driscoll on 4/3/13. | |
// | |
#import "JCDActionSheetDelegate.h" | |
@interface JCDActionSheetDelegate () { | |
JCDActionSheetDelegate *_this; | |
JCDActionSheetDelegateCallback _callback; | |
} | |
@end | |
@implementation JCDActionSheetDelegate | |
- (id)initWithCallback:(JCDActionSheetDelegateCallback)callback | |
{ | |
self = [super init]; | |
if (self) { | |
// We need to retain ourselves | |
_this = self; | |
_callback = [callback copy]; | |
} | |
return self; | |
} | |
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex | |
{ | |
_callback(actionSheet, buttonIndex); | |
// We can release ourselves now | |
_this = nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment