0

I'm attempting to disable paste in a textfield using the following code:

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

  if ([UIMenuController sharedMenuController]) {

    [UIMenuController sharedMenuController].menuVisible = NO;

  }

  return NO;
}

I've this code in other projects and its worked, however in my current project it just gets called multiple times and then displays the paste menu item.

This only thing that I can see that is different is that in this project the viewcontroller where the above code lives is the child of a custom viewcontroller.

EDIT

It's not showing the menu option when I run it with in the simulator with iOS4.3 as opposed to iOS5

wibosco
  • 967
  • 1
  • 11
  • 32

1 Answers1

3

I got there in the end. Instead of placing the code into the viewcontroller, i subclassed UITextField and placed it in there and it works.

I based it on the example here:

How do you REALLY remove Copy from UIMenuController

Community
  • 1
  • 1
wibosco
  • 967
  • 1
  • 11
  • 32
  • Yeah, I found that subclassing the UITextField works in Xcode 5.1. I had the same issue and after much struggling with it came up with this more detailed outline. You are free to use it if you like. http://stackoverflow.com/questions/24514104/how-do-prevent-a-copy-paste-select-popover-on-a-uitextview-using-uimenucontrolle – tony.stack Jul 01 '14 at 17:25