Create a category for class NSObject and swizzle its method.
@interface NSObject (myCanPerformAction)
- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender;
@end
Question
Is it possible to replace method of all objects using it as implementation of a protocol?
The method is canPerformAction:(SEL)action withSender:(id)sender
:
- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender {
return NO;
}
The initial problem: can't disable "Cut, Copy, Paste" and "Select, Select All" popup menu on UIWebView. Some strange object generates them on its canPerformAction
method. And I can't find this object to replace method only on its class.
Very hope to your help. Can't solve this problem for a long time. All other methods to disable selection also disables user input on my page. And I may only replace canPerformAction
method of correct or all classes to get it working.
Solution
Create a category for class NSObject and swizzle its method.
@interface NSObject (myCanPerformAction)
- (BOOL)myCanPerformAction:(SEL)action withSender:(id)sender;
@end