Created
September 20, 2012 14:16
-
-
Save pj4533/3756210 to your computer and use it in GitHub Desktop.
Respond to button events with blocks
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
| #import <UIKit/UIKit.h> | |
| @interface UIControl (ETBlockActions) | |
| - (void) addEventHandler:(void(^)(void))handler forControlEvents:(UIControlEvents)controlEvents; | |
| @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
| #import "UIControl+ETBlockActions.h" | |
| #import <objc/runtime.h> | |
| @implementation UIControl (ETBlockActions) | |
| - (void) addEventHandler:(void(^)(void))handler forControlEvents:(UIControlEvents)controlEvents { | |
| class_addMethod([self class], @selector(eventHandler), imp_implementationWithBlock((__bridge void *)(handler)), "v@:"); | |
| [self addTarget:self action:@selector(eventHandler) forControlEvents:controlEvents]; | |
| } | |
| @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
| #import <UIKit/UIKit.h> | |
| @interface UIControl (ETBlockActions) | |
| - (void) addEventHandler:(void(^)(void))handler forControlEvents:(UIControlEvents)controlEvents; | |
| @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
| #import "UIControl+ETBlockActions.h" | |
| #import <objc/runtime.h> | |
| @implementation UIControl (ETBlockActions) | |
| - (void) addEventHandler:(void(^)(void))handler forControlEvents:(UIControlEvents)controlEvents { | |
| class_addMethod([self class], @selector(eventHandler), imp_implementationWithBlock(handler), "v@:"); | |
| [self addTarget:self action:@selector(eventHandler) forControlEvents:controlEvents]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment