解决调用performSelector产生警告问题

2016-05-07  本文已影响280人  lancely
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);
上一篇下一篇

猜你喜欢

热点阅读