How to manage Copy, Paste, Select All, Define in iPhone UITextView application?

I am working in an iPhone application using a UITextView. I want to allow only the user to copy the message and paste the message . But I do not want to show Select all, Select, Define and others . I follow the code below to control the parameters. But all parameters are displayed in a UITextView click.

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

Can anyone help me do this. And also I do not want to show |.Text.| when copying a message. Please help me do this. Thanks in advance.

+6
source share
2 answers

First of all, if the code above does not work for you, you probably forgot to change the UITextView class to your own class that implements the method above.

After you have done what you have, you must work, and then you must return no to select all.

  if (action == @selector(selectAll:)) { return NO; } 

you can also return no for cut: also assuming that you do not want the user to delete the text from the text file.

In addition, it should not be if else expressions, since they are independent of each other

In fact, they are called in this order.

cut: copy: select: select all: paste: delete:

Thus, remove the functionality as needed.

+2
source

Subclass UITextField and override the canPerformAction: withSender: method in this class.

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

Source: https://habr.com/ru/post/922020/


All Articles