How disable Copy, Cut, Select, Select All in UITextView

Aishwarya picture Aishwarya · Sep 15, 2009 · Viewed 95.7k times · Source

The UITextView's Copy, Cut, Select, Select All functionality is shown by default when I press down on the screen. But, in my project the UITextField is only read only. I do not require this functionality. Please tell me how to disable this feature.

Answer

rpetrich picture rpetrich · Sep 15, 2009

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