views:

88

answers:

2

I'm trying to create a custom UIMenuController and display it in my view. Here's my code:

UIMenuController *menuController = [UIMenuController sharedMenuController];
    UIMenuItem *listMenuItem = [[UIMenuItem alloc] initWithTitle:@"List" action:@selector(addList:)];

    [menuController setMenuItems:[NSArray arrayWithObject:listMenuItem]];
    [menuController setTargetRect:CGRectMake(50.0, 50.0, 0, 0) inView:self.view];
    [menuController setMenuVisible:YES animated:YES];

    [listMenuItem release];

There are no errors or exceptions, but the menu controller just doesn't show up.

A: 

Hi,

maybe because CGRectMake(50.0, 50.0, 0, 0) creates a CGRect with width = 0 and height = 0?

cheers, anka

anka
Even if I set the width/height to something like 100, still doesn't show up.
macatomy
Ok, you can try to add the method (BOOL)canPerformAction:(SEL)action withSender:(id)sender and return YES.
anka
Still doesn't work.
macatomy
+1  A: 

You need to do three things

  1. You need the View to be the firstResponder
  2. You need to implement -(BOOL) canBecomeFirstResponder ...
  3. You need to implement -(BOOL) canPerformAction ...

cheers,

Jayant C Varma

OZ Apps