在自定义视图中,我设置了'canBecomeFirstResponder'以返回YES 并且还定义了' - (BOOL)canPerformAction:(SEL)动作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'通知 如预期的那样。
请任何人帮忙或指出正确的方向。 提前谢谢。
答案 0 :(得分:1)
if(![self becomeFirstResponder]; )
{
NSLog(@"Couldn't become first responder ");
return;
}
首先检查yesFirstResponder。