0

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 ?

Rajesh
  • 10,318
  • 16
  • 44
  • 64
Umer Afzal
  • 371
  • 1
  • 2
  • 18

5 Answers5

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
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
  • that code not working – Umer Afzal Feb 20 '14 at 10:38
  • 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
-1

try this

yourTextView.editable = NO
square
  • 162
  • 2
  • 13