Hide UIMenuController in UITextView

戏子无情 提交于 2019-12-13 18:35:20

问题


Subclassed UITextView

Here is h file

@interface CTextView : UITextView {
}
@end

Here is m file code

#import "CTextView.h"
@implementation CTextView


- (BOOL)canBecameFirstResponder {
return NO;
}
@end

Here is first UIViewController file in which subclassed UITextview is using

#import "First.h"
#import "CTextView.h"


textView = [[[CTextView alloc] initWithFrame:CGRectMake(0, 0, 320, 410)]autorelease];
[self.view addSubview:textView];

But still not able to prevent copy select all from UITextView. Please let me know if i am still missing anything or doing wrong.

Thanks for help.


回答1:


Use this to disable copy:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return NO;
}



回答2:


Got it. Now it is working

Here is the code for reference for anyone need it

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

{    
[UIMenuController sharedMenuController].menuVisible = NO; //do not display the menu
if (action == @selector(copy:))
{

    return NO;  

}

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

}

[self resignFirstResponder];                      //do not allow the user to selected anything
return NO;

return [super canPerformAction:action withSender:sender];
}

Now only problem having is Zooming. Now i have to work on that to disable it from UITextView.




回答3:


Have you set the user interaction enabled to YES?



来源:https://stackoverflow.com/questions/10636880/hide-uimenucontroller-in-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!