Skip to content

Instantly share code, notes, and snippets.

@jdriscoll
Created June 17, 2013 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdriscoll/5798059 to your computer and use it in GitHub Desktop.
Save jdriscoll/5798059 to your computer and use it in GitHub Desktop.
Block-based Action Sheet wrapper
//
// 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
//
// 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