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