tags:

views:

3017

answers:

5

I used UITextView in that Copy, Cut, Select, Select All functionality shows by default when i touches continuously. but in my project the text view property is only read only. I not require this functionality. Please tell me how to disable this function.

+4  A: 

The easiest way is to create a subclass of UITextView that overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:

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

Also see UIResponder

rpetrich
A: 

I have done it. On my UITextView I have disabled cut, copy, select, etc. option very easily.

I placed a UIView at the same place where i had placed the UITextView, but on self.view and added a touchDelegate method as follows:

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *scrollTouch=[touches anyObject];
    if(scrollTouch.view.tag==1)
    {
        NSLog(@"viewTouched");
        if(scrollTouch.tapCount==1)
            [textView1 becomeFirstResponder];
        else if(scrollTouch.tapCount==2)
        {
            NSLog(@"double touch");
            return;
        }

    }
}

and it worked for me. Thank you.

Sumit Prasad
A: 

This is the easiest way to disable the entire Select/Copy/Paste Menu in a UITextView

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

The easiest way is to create a subclass of UITextView that overrides the canPerformAction:withSender:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender    
{    
     [UIMenuController sharedMenuController].menuVisible = NO;  //do not display the menu
     [self resignFirstResponder];                      //do not allow the user to selected anything
     return NO;
}
haiLong
+1  A: 

Subclass UITextView and overwrite canBecomeFirstResponder:

- (BOOL)canBecomeFirstResponder {
    return NO;
}

Note, that this only applies for non-editable UITextViews! Haven't tested it on editable ones...

iCoder