oc消息转发
2021-07-26 本文已影响0人
ONE2
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(foo)];
}
+ (BOOL)resolveInstanceMethod:(SEL)sel {
return [super resolveInstanceMethod:sel];
}
- (id)forwardingTargetForSelector:(SEL)aSelector {
// 指定转发对象
// if(aSelector == @selector(foo)) {
// return [Me new];
// }
return [super forwardingTargetForSelector:aSelector];
}
//
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
if (aSelector == @selector(foo)) {
return [Me instanceMethodSignatureForSelector:aSelector];
}
return [super methodSignatureForSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
if (anInvocation.selector == @selector(foo)) {
[anInvocation invokeWithTarget:[Me new]];
} else {
[super forwardInvocation:anInvocation];
}
}
//- (void)doesNotRecognizeSelector:(SEL)aSelector {
//
//}
@end