-1

在自定义视图中,我将“canBecomeFirstResponder”设置为返回 YES,并且还定义了“- (BOOL)canPerformAction:(SEL)action withSender:(id)sender”

我使用以下代码来显示弹出菜单:

[self becomeFirstResponder];
UIMenuController *theMenu = [UIMenuController sharedMenuController];


if (theMenu.menuItems==nil)
{
    UIMenuItem* item = [[UIMenuItem alloc] initWithTitle:@"Open" action:@selector(openAction:)];
    NSArray* array = [NSArray arrayWithObject:item];
    theMenu.menuItems = array;
    [item release];
}

CGRect rect;
rect = CGRectMake(self.frame.size.width*0.5, self.frame.size.height*0.5, 0, 0);
[theMenu setTargetRect:rect inView:self];
theMenu.arrowDirection = UIMenuControllerArrowDown;
[theMenu setMenuVisible:YES animated:YES];

问题是这在 iOS 5 上运行良好,但在 iOS 4.3 上没有显示任何内容。

然而,在两个 iOS 上,“UIMenuControllerWillShowMenuNotification”和“UIMenuControllerDidShowMenuNotification”通知按预期接收。

任何人都可以帮助或指出我正确的方向。提前致谢。

4

1 回答 1

1
 if(![self becomeFirstResponder]; )
 {
    NSLog(@"Couldn't become first responder ");
    return;
 }

首先检查 becomeFirstResponder。

于 2012-01-10T09:26:04.500 回答