Disable UITextview
selection disable or disable copy/paste menu but I want not disable my links in UITextview
I try but both are disable any solution ?
Asked
Active
Viewed 1,318 times
0

Rajesh
- 10,318
- 16
- 44
- 64

Umer Afzal
- 371
- 1
- 2
- 18
-
Show the code that you used – Samkit Jain Feb 20 '14 at 08:41
-
[textview setSelectable:No]; – Umer Afzal Feb 20 '14 at 08:42
-
that code disable my web links in uitextview not press able – Umer Afzal Feb 20 '14 at 08:43
-
post your code then we can know what is issue – square Feb 20 '14 at 08:44
-
i implement all anwser but copy /paste menu still showing – Umer Afzal Feb 20 '14 at 10:28
-
https://www.dropbox.com/s/82mgtip0bb2xt2h/Untitled.png i want this – Umer Afzal Feb 20 '14 at 10:49
-
any solution i already check all answers – Umer Afzal Feb 20 '14 at 10:49
5 Answers
2
if you simply want to disable copy/ paste. you should use a Subclass for your UITextView
then simply do this to disable all items from the menu:
- (BOOL)canBecomeFirstResponder {
return NO;
}
if you only want to disable copy and paste, you can do:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:) || action == @selector(copy:))
return NO;
return [super canPerformAction:action withSender:sender];
}

Xu Yin
- 3,932
- 1
- 26
- 46
1
in – textViewDidChangeSelection: delegate method,
textView.selectedRange = NSMakeRange(0,0);

santhu
- 4,796
- 1
- 21
- 29
-
i use this textView.selectedRange = NSRangeMake(0,0); but copy /paste menu and selection working – Umer Afzal Feb 20 '14 at 08:46
1
Implement the following as per your requirement. it will work for sure:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(selectAll:))
return NO;
if (action == @selector(select:))
return NO;
if (action == @selector(cut:))
return NO;
if (action == @selector(copy:))
return NO;
if (action == @selector(paste:))
return NO;
return [super canPerformAction:action withSender:sender];
}

Samkit Jain
- 2,523
- 16
- 33
1
You can over ride UITextField
for - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
. See below code -
@interface MYLoginTextField : UITextField
@end
@implementation MYLoginTextField
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(paste:) || action == @selector(copy:) || action == @selector(cut:) || action == @selector(select:) || action == @selector(selectAll:) || action == @selector(select:))
return NO;
return [super canPerformAction:action withSender:sender];
}
@end

nswamy
- 1,041
- 9
- 16
-
-
How exactly did you try this? I have updated the complete code taken from my working project. – nswamy Feb 21 '14 at 09:17
-
i use this code in subclass that can't press links in textview and not showing copy/paste menu. - (BOOL)canBecomeFirstResponder { return NO; } then i write this code then allow to press links but in other text show "Define" - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(selectAll:) && action == @selector(select:) && action == @selector(cut:) && action == @selector(copy:) && action == @selector(paste:)) return NO; return [super canPerformAction:action withSender:sender]; } plz help me in this case. – Umer Afzal Feb 24 '14 at 04:28