0
votes

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];


}
1

1 Answers

0
votes

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).

More details can be found here: How do you REALLY remove Copy from UIMenuController