美文网首页
oc消息转发

oc消息转发

作者: ONE2 | 来源:发表于2021-07-26 21:35 被阅读0次
    @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
    

    相关文章

      网友评论

          本文标题:oc消息转发

          本文链接:https://www.haomeiwen.com/subject/udugmltx.html