如何在iOS中的menucontroller中禁用粘贴选项? [英] How to disable paste option in menucontroller in iOS?

查看:103
本文介绍了如何在iOS中的menucontroller中禁用粘贴选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户长按UITextField时,我必须禁用粘贴选项。我有这个代码,但它仍然没有隐藏粘贴选项。

I have to disable Paste option when user long press on UITextField.I have got this code but still it is not hiding Paste option.

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

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

    }
    return NO;  
}

任何人都可以帮助我吗?

Can any one help me?

推荐答案

正如评论中已经说过的那样..你需要在UITextField的子类中包含完全相同的代码,然后使用该类的实例

As already said in comments.. you need to "include the exact same code in a subclass of UITextField and then use instances of that class"

所以..创建新文件..让我们说TestTaste .. UITextField的子类

so.. create new file .. let's say TestPaste.. subclass of UITextField

将您的代码放入实施文件(TextPaste.m)

put your code in implementation file (TextPaste.m)

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

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

    }
    return NO;  
}

现在。转到你的NIB / Storyboard,点击你的UITextFiled并将textview类更改为你的TextPaste

now. go to your NIB/Storyboard, click on your UITextFiled and change the textview class to your TextPaste

这篇关于如何在iOS中的menucontroller中禁用粘贴选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆