在复制所有文本后,隐藏复制和取消选择UITextView选项 [英] Hide Copy and Deselect UITextView options after copying all text

查看:457
本文介绍了在复制所有文本后,隐藏复制和取消选择UITextView选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通讯应用程式。当用户在 UITextView 中输入消息时,我想给用户一个复制选项。当用户按下复制按钮时,它正在复制消息,但弹出框一再显示,文本仍然可选。

I am working on a messaging app. I want to give a "copy" option to the user when they enter their message in a UITextView. When the user presses the "copy" button, it is copying the message, but the popover shows again and again, and the text is still selectable.

知道如何控制这个。我已经粘贴了一些源代码供您参考。

I don't know how to control this. I have pasted some source code for your reference.

我为 UITextView 写了一个子类。

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    NSLog(@"Action : %@", NSStringFromSelector(action));
    NSLog(@"Sender : %@", sender);
    if (action == @selector(copy:))
    {
        [self selectAll:self];
        //return [super canPerformAction:action withSender:sender];
        return YES;
    }
    else if (action == @selector(cut:))
    {
        return NO;
    } 
        return NO;
}


推荐答案

如果您使用iOS5

UITextView 采用 UITextInput 协议, selectedTextRange 属性。将属性设置为nil:

UITextView adopts the UITextInput protocol, which has a selectedTextRange property. Set the property to nil:

在最后返回NO 上添加以下代码。

Add the below code just above the last return NO.

self.selectedTextRange = nil;

希望这有助于

这篇关于在复制所有文本后,隐藏复制和取消选择UITextView选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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