点击UITextField即可禁用菜单

时间:2012-02-20 20:00:20

标签: iphone objective-c ios cocoa-touch uitextfield

当点击UITextField时,我们如何禁用Cut-Copy-Paste或Select-SelectAll菜单。我尝试使用下面的代码,但它没有用。

if ([UIMenuController sharedMenuController]) {
    [UIMenuController sharedMenuController].menuVisible = NO;
}

2 个答案:

答案 0 :(得分:2)

如果是UITextView,则创建一个子类并实现此函数

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
   if (action == @selector(paste:) || action == @selector(copy:))//and put other actions also
    return NO;
return [super canPerformAction:action withSender:sender];
}

答案 1 :(得分:0)

canBecomeFirstResponderhere应该做到这一点。确保您委派了UITextField

- (BOOL)canBecomeFirstResponder {
    return NO;
}