I have two UIViewController, one is the main and from this trough a button you can go to the second. In SecondView.m I have the following code:
- (IBAction)showpopup:(id)sender {
[self becomeFirstResponder];
UIMenuController *sharedController = [UIMenuController sharedMenuController];
UIMenuItem *x2 = [[UIMenuItem alloc] initWithTitle:@"2x2" action: @selector(mat)];
UIMenuItem *x3 = [[UIMenuItem alloc] initWithTitle:@"3x3" action: @selector(mat)];
UIMenuItem *x4 = [[UIMenuItem alloc] initWithTitle:@"4x4" action: @selector(mat)];
UIMenuItem *x5 = [[UIMenuItem alloc] initWithTitle:@"5x5" action: @selector(mat)];
NSArray *menuArray = [NSArray arrayWithObjects: x2,x3,x4,x5, nil];
CGRect drawRect = [sender convertRect:[sender bounds] toView: self.view];
[sharedController setTargetRect:drawRect inView: self.view];
[sharedController setMenuItems:menuArray];
[sharedController setMenuVisible:YES animated:YES];
[sharedController setMenuItems: nil];
}
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(int)mat:(id)sender{
return 0;
}
The Button is linked as "touch up inside", but when I run the UIMenuController doesn't show up. The exact same code works in the main UIViewController.
Thanks