我在 viewDidLoad 中以编程方式创建我的 UITextView。
当我选择文本时,菜单会显示以下内容:
如图所示,我添加了两个自定义按钮,突出显示和取消突出显示。我想删除“复制”选项并保留所有其他选项,所以我不能使其不可编辑,我需要允许用户从文本中选择他想要的任何内容,但阻止它复制内容。
我尝试了几种方法,包括所有社区所指的方法:
- (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];
}
为了更好地查看问题,如果选择器实际上考虑了“复制”选项,我尝试注销,这是我的日志:
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
如图所示,代码正在调用“canPerformAction”,因为日志显示“它进入 canPerform”,但它没有识别“复制”操作,因为日志从未显示:“它阻止了复制选项并将其隐藏菜单”。
因此,我的问题是我需要从选定的文本菜单中隐藏“复制”项目。我错过了什么?