Created
March 27, 2014 14:16
-
-
Save kluivers/9808519 to your computer and use it in GitHub Desktop.
Responder forwarding
This file contains 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
@implementation UIResponder (ResponderForwarding) | |
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object | |
@end | |
@implementation UIResponder (ResponderForwarding) | |
- (BOOL) tryToPerformAction:(SEL)action withObject:(id)object | |
{ | |
if (!action) { | |
return NO; | |
} | |
id target = [[self nextResponder] targetForAction:action withSender:self]; | |
if (target) { | |
NSMethodSignature *signature = [[target class] instanceMethodSignatureForSelector:action]; | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | |
invocation.target = target; | |
invocation.selector = action; | |
[invocation setArgument:&object atIndex:2]; | |
[invocation invoke]; | |
return YES; | |
} | |
return NO; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage