从UIMenuController删除副本并定义 [英] Remove copy and define from UIMenuController
问题描述
我有UIWebView用于显示一些文章.我需要从UIWebView中选择一些文本并使用书签.所以我使用的是selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
,但是当我长按UIMenuItem时,显示的是copy,define.我阅读了一些文档,并使用了canPerformAction:
复制NO.但是它仍然显示.
I have UIWebView for displaying some articles. I need to select some text from UIWebView and use bookmark. So i'm using selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
But when i longpress the UIMenuItem displays with copy,define. I read some doc and used canPerformAction:
copy NO. But still it displaying.
- (void)viewDidLoad
{
[wbCont loadHTMLString:webString baseURL:nil];
[self.view addSubview:wbCont];
NSMutableArray *items = [[[UIMenuController sharedMenuController] menuItems] mutableCopy];
if (!items) items = [[NSMutableArray alloc] init];
UIMenuItem *menuItem;
menuItem = [[UIMenuItem alloc] initWithTitle:@"BookMark" action:@selector(book:)];
[items addObject:menuItem];
[menuItem release];
menuItem = [[UIMenuItem alloc] initWithTitle:@"Note" action:@selector(note:)];
[items addObject:menuItem];
[menuItem release];
[[UIMenuController sharedMenuController] setMenuItems:items];
[items release];
}
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
{
return NO;
}
if (action == @selector(book:))
{
return YES;
}
else if (action == @selector(note:))
{
return YES;
}
return [super canPerformAction:action withSender:sender];
}
推荐答案
您必须将UIWebView子类化. (创建一个新的Objective-C类并选择UIWebView的子类.)
You have to subclass UIWebView. (Create a new Objective-C class and select subclass of UIWebView).
在您的子类中编写方法:
Within your subclass write the method:
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender{
if (action == @selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
如果要在自定义选择器中添加自定义选择器,则无需在其中设置自己的自定义选择器(因为我想这就是您要做的事情).
You don't need to set you own custom selectors there if you are adding them inside your contoller (as I guess that's what you where doing).
更多详细信息可以在这里找到:如何做您真的从UIMenuController删除了复制
More details can be found here: How do you REALLY remove Copy from UIMenuController
这篇关于从UIMenuController删除副本并定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!