美文网首页
解决调用performSelector产生警告问题

解决调用performSelector产生警告问题

作者: lancely | 来源:发表于2016-05-07 12:14 被阅读280次
    if ([self.dockView respondsToSelector:NSSelectorFromString(@"setSubViews")]) {
        // 这样会产生警告
        // [self.dockView performSelector:NSSelectorFromString(@"setSubViews")];
        SEL selector = NSSelectorFromString(@"setSubViews");
        IMP imp = [self.dockView methodForSelector:selector];
        void (*func)(id, SEL) = (void *)imp;
        func(self.dockView, selector);
    }
    

    下面是带参数情况

    SEL selector = NSSelectorFromString(@"processRegion:ofView:");
    IMP imp = [_controller methodForSelector:selector];
    CGRect (*func)(id, SEL, CGRect, UIView *) = (void *)imp;
    CGRect result = func(_controller, selector, someRect, someView);
    

    相关文章

      网友评论

          本文标题:解决调用performSelector产生警告问题

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