美文网首页
iOS 消息转送 与 消息禁用

iOS 消息转送 与 消息禁用

作者: Lifeasy | 来源:发表于2017-03-24 17:58 被阅读20次
    消息转送
    • 重写respondsToSelector
    - (BOOL)respondsToSelector:(SEL)aSelector {
        if ([super respondsToSelector:aSelector]) {
            return YES;
        } else if ([self methodForSelector:aSelector] != (IMP)NULL) {
            return YES;
        } else {
            return [self.someObj respondsToSelector:aSelector];
        }
        return NO;
    }
    
    - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
        if ([super respondsToSelector:aSelector]) {
            return [super methodSignatureForSelector:aSelector];
        }
        return [self.someObj methodSignatureForSelector:aSelector];
    }
    
    - (void)forwardInvocation:(NSInvocation *)anInvocation {
        SEL selector = [anInvocation selector];
        if ([self.someObj respondsToSelector:selector]) {
            [anInvocation invokeWithTarget:self.third];
        } else {
            [super forwardInvocation:anInvocation];
        }
    }
    
    消息禁用
    - (void)setSize:(NSSize *)size {
        [self doesNotRecognizeSelector:_cmd];
    }
    

    相关文章

      网友评论

          本文标题:iOS 消息转送 与 消息禁用

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