Note that there are some explanatory texts on larger screens.

plurals
  1. POUse standard Copy and retrieve value from the UIPasteboard with a custom UIMenuController item
    primarykey
    data
    text
    <p>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</p> <pre><code>[[UIApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self forEvent:nil]; </code></pre> <p>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.</p> <p>This is my code (simplified) In the view did load i've added one observer for UIPasteboardChangedNotification for perform my selector myCopy:</p> <pre><code>- (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 } </code></pre> <p>Thank you for your help and for your time!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload