1
votes

I have UIWebView. I need to select some text from UIWebView. So im using UIMenuController for MenuItem. I need to display UIMenuController while button click. But it's not working. If i paste the code inside ViewDidLoad it's working.

code:

[wbCont loadHTMLString:webString baseURL:nil];
    [self.view addSubview:wbCont];

    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake(80.0, 120.0, 160.0, 40.0);
        [button addTarget:self
                   action:@selector(show:)
         forControlEvents:UIControlEventTouchDown];
        [button setTitle:@"Shows" forState:UIControlStateNormal];
        [self.view addSubview:button];

-(void)show:(id)sender{


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

}
1

1 Answers

1
votes

Probably a little bit too late, as it was asked two years ago, but if anyone - like me - comes across:

You've forgot to make the menuController visible.

[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];

at the end of you -(void)show:(id)sender; method should have done it.

cheers ;)