0

Possible Duplicate:
How disable Copy, Cut, Select, Select All in UITextView

I have a UITextView which can be edited. I have another button for "Copy", so I want to disable the built-in "Copy" and "Cut" features of the text view. These are shown as a black mini popover when double tapping inside the text view. Is there any way to block only these two options and still let the user edit the text?

Community
  • 1
  • 1
Pradeep Rajkumar
  • 919
  • 2
  • 12
  • 27

2 Answers2

6

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;
        if (action == @selector(select:))   
            return NO;   
        if (action == @selector(selectAll:))   
            return NO;  
        return [super canPerformAction:action withSender:sender];
    }

Another way

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

Also check This link

iPatel
  • 46,010
  • 16
  • 115
  • 137
-2

Subclass UITextView and overwrite canBecomeFirstResponder:

- (BOOL)canBecomeFirstResponder
{
    return NO;
}

Hope this helps you..

P.J
  • 6,547
  • 9
  • 44
  • 74
  • -1, this answer is wrong. This makes the text view uneditable. The OP explicitly asked for a solution that leaves the text view editable. – Mark Amery Aug 22 '13 at 11:29