【问题标题】:Is it possible to replace method of all objects using it as implementation of a protocol?是否可以使用它作为协议的实现来替换所有对象的方法?
【发布时间】:2012-11-07 14:20:15
【问题描述】:

是否可以使用它作为协议的实现来替换所有对象的方法?

方法是canPerformAction:(SEL)action withSender:(id)sender:

- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender {
    return NO;
}

最初的问题:无法禁用 UIWebView 上的“剪切、复制、粘贴”和“全选”弹出菜单。一些奇怪的对象在其canPerformAction 方法上生成它们。而且我找不到这个对象来替换它的类上的方法。

非常希望对您有所帮助。很长一段时间都解决不了这个问题。所有其他禁用选择的方法也会禁用我页面上的用户输入。而且我只能替换正确的canPerformAction 方法或所有类以使其正常工作。

【问题讨论】:

    标签: objective-c uiwebview uimenucontroller swizzling


    【解决方案1】:

    为 NSObject 类创建一个类别并调整其方法。

    @interface NSObject (myCanPerformAction)
    
    - (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender;
    
    @end
    

    【讨论】:

      猜你喜欢
      • 2011-01-27
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多