Skip to content

Instantly share code, notes, and snippets.

@alexdrone
Created April 18, 2012 14:52
Show Gist options
  • Save alexdrone/2414096 to your computer and use it in GitHub Desktop.
Save alexdrone/2414096 to your computer and use it in GitHub Desktop.
UIButton with blocks
typedef void (^ActionBlock)();
@interface UIBlockButton : UIButton {
@private
ActionBlock _actionBlock;
}
-(void) handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock) action;
@implementation UIBlockButton
-(void) handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock) action
{
_actionBlock = Block_copy(action);
[self addTarget:self action:@selector(callActionBlock:) forControlEvents:event];
}
-(void) callActionBlock:(id)sender
{
_actionBlock();
}
-(void) dealloc{
Block_release(_actionBlock);
[super dealloc];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment