Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting copy,paste option for a particular UITextfield

My UIView contains Two UITextField.I need to restrict copy,paste option for one textfield.I don't want to restrict that for another.

When i am using the following code,Both the field gets restricted from copy,paste.

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{
    if ( [UIMenuController sharedMenuController] )
    {
            [UIMenuController sharedMenuController].menuVisible = NO;
    }
     return NO;
}

Can any one provide me the solution to solve my problem.

like image 969
EXC_BAD_ACCESS Avatar asked Nov 25 '10 16:11

EXC_BAD_ACCESS


1 Answers

Create a subclass of UITextField. In that subclass, implement

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

Then use this subclass for the field that you don't want to be able to copy in, and use a regular UITextField for the one that you can copy from.

like image 72
Lily Ballard Avatar answered Jan 24 '23 09:01

Lily Ballard