Remove "Copy" menu item from programatically created UITextView IOS

I create my UITextView programmatically in my viewDidLoad.
When i select a text, the menu shows me the following :

enter image description here

As it shows, i have added two custom buttons the highlight and unhighlight. I would like to remove the ” copy ” option and keep all others, so i cannot make it Un-Editable, i need to allow the user to select whatever he wants from the text, but prevent it from copying the content.
I have tried several methods, including this one which all the community is referring to :

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
     NSLog(@"it went in canPerform");
     if (action == @selector(copy:)){

          NSLog(@"It prevented the copy option and hid it from the menu");
          return NO;

     }
     return [super canPerformAction:action withSender:sender];
}

In order to have a better look at the problem, i tried to log out if the selector is actually taking into consideration the “Copy” option, this is my log :

2015-05-20 11:27:47.637 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.637 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.638 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.663 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

2015-05-20 11:27:47.664 MyApp[56604:11786730] it went in canPerform

As it shows, the code is calling the “canPerformAction” since the log shows “It went in canPerform”, but it’s not recognizing the “copy” action, since the log never showed : “It prevented the copy option and hid it from the menu”.
Therefor, my problem is that i need to hide the “Copy” item from the selected text menu. What am i missing ?


Source: ios

Leave a Reply