oc 基础 - runtime - 方法交换

82 阅读1分钟

method run = objc_getInstenceMethod(@select(run); method text = objc_getInstenceMethod(@select(run);

method _exchangeImp(run,text);

案例 链接 button 点击事件

[sendAction:(SEL)action to:(id) forEvent:(id)event];

分类 UIcontrol+extension

+load { method action1 = objc_getInstenceMethod(@select(sendAction:(SEL)action to:(id) forEvent:(id)event); method action2 = objc_getInstenceMethod(@select(abc_sendAction:(SEL)action to:(id) forEvent:(id)event); method _exchangeImp(action1,action2); }

  • (void)abc_sendAction:(SEL)action to:(id) forEvent:(id)event { nslog();

    if (self iskineof(UIbutton class)) { [调用自己 self abc_sendAction....]; } }