0

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

我已将这些方法添加到作为委托的视图控制器中,但我认为它们不是必需的,因为我想要标准的菜单控制器、选择、复制等。更不用说它们没有被调用。

谢谢您的帮助

- (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;
}
4

1 回答 1

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];

您还应该覆盖-copy、-cut、-paste 等方法。

于 2011-07-06T21:09:09.987 回答