0

I'm trying to get UIMenuController to display a menu.

Here is the code I have so far:

commentCell.userInteractionEnabled = YES;
[commentCell becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
    return;
}
menu.menuItems = @[[[UIMenuItem alloc] initWithTitle:@"copy" action:@selector(log)], [[UIMenuItem alloc] initWithTitle:@"report" action:@selector(log)]];
const CGRect targetFrame = commentCell.frame;
const CGRect convertedFrame = [commentCell convertRect:targetFrame toView:self.viewController.view];
[menu setTargetRect:convertedFrame inView:self.viewController.view];
[menu update];
[menu setMenuVisible:YES animated:YES];

Unfortunately, it seems that my menu is not displaying. I tried to follow the guidelines outlined in: UIMenuController not showing up but I've already tried all the suggestions including making my view implement canBecomeFirstResponder and setting userInteractionEnabled to YES. Any ideas what might be the issue or how I can debug further?

MichaelGofron
  • 1,310
  • 4
  • 15
  • 29

2 Answers2

0

Figured out the problem. It turns out I needed to also include the field: -(BOOL)canPerformAction in self.viewController

MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
0

I want to add an issue that the targetFrame should be:

const CGRect targetFrame = commentCell.bounds;

E.Coms
  • 11,065
  • 2
  • 23
  • 35