【问题标题】:no uimenucontroller with uitextview showing, universal app xcode 4没有显示 uitextview 的 uimenucontroller,通用应用程序 xcode 4
【发布时间】:2011-07-06 19:37:49
【问题描述】:

在模拟器上,我看到 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;
}

【问题讨论】:

    标签: iphone ipad xcode4 uitextview uimenucontroller


    【解决方案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 等等。

    【讨论】:

    • 即使是为了获得标准的选择、复制、粘贴也必须这样做?我以为是非标准菜单。顺便说一句,我可以在模拟器中看到它们,只是在设备上看不到。
    • 我可能弄错了——我离开了我的 Mac,但现在我意识到,由于我的应用程序使用 Core Text,我可能需要该代码,而您的可能不需要。由于文档强烈建议覆盖标准的剪切/复制/粘贴方法,您可以尝试看看它是否能解决问题。
    • 如果有机会请告诉我,我的印象是标准的复制/粘贴总是以 uitextview 出现,但这不是我看到的行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多