我有两个 UIViewController,一个是主要的,通过这个按钮可以转到第二个。在 SecondView.m 我有以下代码:
- (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;
}
Button 链接为“内部修饰”,但是当我运行 UIMenuController 时没有显示。完全相同的代码在主 UIViewController 中工作。
谢谢