如何在 UITextView iPhone 应用程序中控制复制、粘贴、全选、定义? [英] How control Copy, Paste, Select All, Define in UITextView iPhone app?

查看:36
本文介绍了如何在 UITextView iPhone 应用程序中控制复制、粘贴、全选、定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UITextView 在 iPhone 应用程序中工作.我想允许用户只能复制消息和粘贴消息.但我不想显示全选、选择、定义和其他.我正在按照下面的代码来控制选项.但是,所有选项都显示在 UITextView 单击中.

I am working in the iPhone app using UITextView. I want to allow the user only can Copy the message and Paste the message. But i don't want to show Select all, Select, Define and others. I am following this below code to control the options. But, all the options are showing in UITextView click.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
    {
        return NO;
    }
    else if (action == @selector(copy:))
    {
        return NO;
    }

    return [super canPerformAction:action withSender:sender];
}

任何人都可以帮助我做到这一点.而且我不想在复制消息时显示 |.Text.| .请帮我做这件事.提前致谢.

Can anyone please help me to do this. And also i don't want to show |.Text.| while copying the message. Please help me to do this. Thanks in advance.

推荐答案

首先,如果您上面的代码不起作用,那么您可能忘记将 UITextView 的类更改为实现上述方法的自定义类.

First of all if the code you have above isn't working then you probably forgot to change the class of you UITextView to your custom class that implements the method above.

一旦你完成了你所拥有的应该工作,然后你也应该为 select all 返回 no

Once you've done that what you've got should work and you should then return no for select all also

   if (action == @selector(selectAll:))
        {
            return NO;
        }

您也可能希望返回 no for cut:还假设您不希望用户从 textView 中删除文本.

also you may want to return no for cut: also assuming you don't want the user to remove text from the textView.

这些也不需要是 if else 语句,因为它们不相互依赖

Also these don't need to be if else statements as they don't depend on each other

实际上是按这个顺序调用的

They are actually called in this order

剪切:复制:选择:全选:粘贴:删除:

cut: copy: select: selectAll: paste: delete:

因此请酌情删除功能.

这篇关于如何在 UITextView iPhone 应用程序中控制复制、粘贴、全选、定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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