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

iOS-解决调用performSelector产生警告问题

作者: 23b813a14221 | 来源:发表于2018-06-20 14:57 被阅读0次

    ///不需要带参数情况
    if ([self.view respondsToSelector:NSSelectorFromString(@"setSubViews")])
    {
    // 这样会产生警告
    // [self.view performSelector:NSSelectorFromString(@"setSubViews")];
    SEL selector = NSSelectorFromString(@"setSubViews");
    IMP imp = [self.view methodForSelector:selector];
    void (*func)(id, SEL) = (void *)imp;
    func(self.view, 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);

    相关文章

      网友评论

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

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