2

I don't want the Copy / Define button to appear when select a text. How can i do that in objective c ?

UPDATE: i want to do that in UIWebView

  • http://stackoverflow.com/questions/27747140/how-to-disable-copy-define-uimenuitems-of-uimenucontroller-in-uitextfield-ios – Mahmoud Adam Jun 16 '15 at 19:39
  • i want to do that in web view not text field –  Jun 16 '15 at 20:00
  • 1
    `canPerformAction:withSender:` is in `UIResponder` which is a common ancestor for both `UITextView` and `UIWebView` – Mahmoud Adam Jun 16 '15 at 20:05
  • i did that with web view but only Define button disappeared and Copy button still appears when select a text. –  Jun 16 '15 at 20:32

2 Answers2

1

The easiest way to disable pasteboard operations is to create a subclass of UITextView that overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}

Also see UIResponder

Answer from this question posted by rpetrich

Community
  • 1
  • 1
Totka
  • 627
  • 6
  • 24
0

Here are all actions sent to `canPerformAction:withSender:

cut:
copy:
select:
selectAll:
paste:
delete:
_promptForReplace:
_transliterateChinese:
_showTextStyleOptions:
_define:
_addShortcut:
_accessibilitySpeak:
_accessibilitySpeakLanguageSelection:
_accessibilityPauseSpeaking:
makeTextWritingDirectionRightToLeft:
makeTextWritingDirectionLeftToRight:

so what you need to remove Copy/Define is the following

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:))
        return NO;
    if (action == @selector(_define:))
        return NO;

    return [super canPerformAction:action withSender:sender];
}
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62