i've a web view with displayed a pdf file. As a standard for the web view the user can select a text and perform standard operation like copy, cut. I need to add a custom UIMenuController for show custom action. I do not understand how to copy the selected text in the standard UIPasteboard and pass to my custom selector. I've tried to use
[[UIApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self forEvent:nil];
in method and i'm able to copy the selected text but i do not understand how to come back this value to my method.
This is my code (simplified) In the view did load i've added one observer for UIPasteboardChangedNotification for perform my selector myCopy:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myCopy:) name:UIPasteboardChangedNotification object:nil];
UIMenuItem *schedaMenuItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"POPSCHEDA",nil) action:@selector(copyScheda:)];
UIMenuItem *istruzionetMenuItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"POPISTR",nil) action:@selector(copyIstruzione:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:MenuItem1,MenuItem2,nil]];
}
-(void)myCopy:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString* copyCode = pasteboard.string;
//perform the necessary action
}
-(void)copyScheda:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString* copyCode = pasteboard.string;
//perform the necessary action
}
-(void)copyIstruzione:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString* copyCode = pasteboard.string;
//perform the necessary action
}
Thank you for your help and for your time!