0
我有用於顯示一些文章的UIWebView。我需要從UIWebView中選擇一些文本並使用書籤。所以我使用selection = [wbCont stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
但是,當我長時間UIMenuItem顯示與複製,定義。我讀了一些文檔並使用canPerformAction:
複製NO。但它仍然顯示。刪除複製並從UIMenuController定義
- (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];
}