没有uimenucontroller与uitextview显示,通用的应用程序xcode 4

时间:2011-07-06 19:37:50

标签: iphone ipad xcode4 uitextview uimenucontroller

在模拟器上,我看到UIMenucontroller没有问题,但它不会出现在运行iOs 4+的设备上进行测试。这是使用IB添加的标准uitextview。

我已将这些方法添加到作为委托的viewcontroller中,但我认为它们不是必需的,因为我需要标准的menucontroller,select,copy等。更不用说它们没有被调用。

感谢您的帮助

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {

    NSLog(@"Can perform action called");

    BOOL answer = NO;

    if (action == @selector(copy:))
    {
        answer = YES;
    }
    if (action == @selector(cut:))
    {
        answer = YES;     
    }
    if (action == @selector(paste:))
    {
        answer = YES;
    }
    if (action == @selector(select:))
    {
        answer = YES;
    }
   if (action == @selector(selectAll:))
    {
        answer = YES;
    }

    return answer;
}

- (BOOL) canBecomeFirstResponder {
    NSLog(@"can become first called");
    return YES;
}

1 个答案:

答案 0 :(得分:1)

您需要添加手势识别器,或覆盖touchesEnded:withEvent:方法,并显示菜单控制器:

//Assumes you assigned a CGRect for where the menu should appear to theRect
UIMenuController *mc = [UIMenuController sharedMenuController];
[mc setTargetRect:theRect inView:self];
[mc setMenuVisible:YES animated:YES];

您还should override the methods -copy,-cut,-paste等