2011-10-29 118 views
-1

在自定義視圖中,我設置了'canBecomeFirstResponder'返回YES 並且還定義了 - (BOOL)canPerformAction:(SEL)action withSender:(id)發件人UIMenuController不在iOS 4上顯示,但在iOS 5上運行

我用下面的代碼顯示彈出式菜單:

[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什麼。

但是雙方iOSes的「UIMenuControllerWillShowMenuNotification」 和「UIMenuControllerDidShowMenuNotification」通知收到 預期。

任何人都可以幫助或指點我正確的方向請。 在此先感謝。

回答

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

先檢查becomeFirstResponder。

+0

http://stackoverflow.com/questions/2487844/simple-way-to-show-the-copy-popup-on-uitableviewcells-like-the-address-book-ap –

相關問題