2013-10-10 38 views
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]; 


} 

回答

0

您必須繼承UIWebView。 (創建一個新的Objective-C類並選擇UIWebView的子類)。

在子類寫的方法:

- (BOOL) canPerformAction:(SEL)action withSender:(id)sender{ 
if (action == @selector(copy:)) 
{ 

return NO; 

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

你並不需要設置你自己的自定義選擇那裏,如果你正在你的位指示內加入他們(我想這就是你在哪裏這樣做)。

更多細節可在這裏找到:How do you REALLY remove Copy from UIMenuController