我有 UIWebView 用于显示一些文章。我需要从 UIWebView 中选择一些文本并使用书签。所以我正在使用selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
但是当我长按 UIMenuItem 显示时复制,定义。我阅读了一些文档并使用了canPerformAction:
副本 NO。但它仍然显示。
- (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];
}