0

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?

P.J
  • 6,547
  • 9
  • 44
  • 74
Apple_Magic
  • 477
  • 8
  • 26

4 Answers4

4

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"

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

enter image description here

put your code in implementation file (TextPaste.m)

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

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

    }
    return NO;  
}

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

enter image description here

TonyMkenu
  • 7,597
  • 3
  • 27
  • 49
1

Piya just check this below link :-

http://eureka.ykyuen.info/2010/04/12/iphone-disable-the-cutcopypaste-menu-on-uitextfield/

You can also check this code :-

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}
trace
  • 21
  • 4
1

You have to create a new Class-> subclass of UITextField .. then in your code/xib change the textview class to your Custom Class.. and the add the method in your custom TextField class

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

It will work then

Shubhank
  • 21,721
  • 8
  • 65
  • 83
0

Use this

@implementation UITextFiels (DisableCopyPaste)

- (BOOL)canBecomeFirstResponder
{
    return NO;
}

@end
amar
  • 4,285
  • 8
  • 40
  • 52