UIMenuController is not showing

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) {
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?

2 answers

  • answered 2018-11-07 22:31 MichaelGofron

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

  • answered 2018-11-07 23:11 E.Coms

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

    const CGRect targetFrame = commentCell.bounds;