views:

2483

answers:

3

Hello everybody,

Does any one know, how can i disable cut, copy and paste option on iPhone 3.0?

Thanks for your help and time.

+2  A: 

Any responder (UIView or UIWindow subclass) can override the canPerformAction:withSender: method, so you could just return NO for all the actions you don't want to permit.

See the UIResponder documentation...

David Maymudes
Thanks David for your reply, but unfortunately it's just a week i started with iphone development. Would you mind telling me how to use this instance method? An sample code would be great. On my UI view, i've two text controls and for both of them i want to disable this.
It looks like you'll have to make a subclass of UITextField that overrides canPerformAction and then use that class for your entry fields. I don't think that's all that hard to do, but I am new enough to Objective C that I would have to take a while to figure the details out; perhaps somebody else can give an example.
David Maymudes
+1  A: 

I, too, couldn't find much documentation on using canPerformAction:withSender: for this purpose. So, I settled for clearing the pasteboard when exiting the application. In my AppDelegate.m:

- (void)applicationWillTerminate:(UIApplication *)application {

  NSLog(@"application terminating");

  // Clear pasteboard to prevent pasting into other applications:
  UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  pasteBoard.items = nil;

}

This worked well for my user-annotated reference application. I don't mind users copying and pasting within my application, but I'd rather they not republish my original content.

At some point I'd like more fine-grained control, perhaps with canPerformAction:withSender:, so that I can allow users to copy/paste the content they do create themselves.

tinymagic
+1  A: 

Override this method in the controller class.

// Hide cut/copy/paste menu

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

if ( [UIMenuController sharedMenuController] )
{
    [UIMenuController sharedMenuController].menuVisible = NO;

}
return NO;

}

iamiPhone