我是否有可能在运行时替换UIWebView的方法体,这很有趣?
我不能继承UIWebView
例如,我需要实现:
- (void) paste:(id)sender;
or
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender;
最佳答案
您是否尝试过运行时方法method_setImplementation
?
像这样:
static IMP originalPaste = NULL;
void myPaste(id rcv, SEL cmd, id sender)
{
// Your implementation here
}
…
{
…
Method m = class_getInstanceMethod([UIWebView class], @selector(paste:));
originalPaste = method_setImplementation(m, myPaste);
…
}
使用
originalPaste
,您可以在实现中执行 super 调用。
关于ios - 是否可以在不子类化的情况下替换UIWebView中现有方法的主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11345864/