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

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);
posted @ 2016-08-18 09:30  lancely  阅读(1067)  评论(0编辑  收藏  举报