-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では正常に機能しますが、iOS4.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 に答える