How does the iphone display menus and perform copy operations?
1. First, you must display the menu
// First turn yourself into the first response <br/> [self becomeFirstResponder]; <br/> // obtain the menu Controller <br/> UIMenuController * copyMenuController = [UIMenuController sharedMenuController]; </p> <p> // set the display position <br/> [copyMenuController setTargetRect: CGRectMake (15, 15,100, 50) inView: self. view]; <br/> // display <br/> [copyMenuController setMenuVisible: YES animated: YES]; </p> <p>
2. Then, you need to change your ViewController to firstResponder.
RESPONSE:-(BOOL) canBecomeFirstResponder
-(BOOL) canBecomeFirstResponder <br/>{< br/> return YES; <br/>}
3. RESPONSE:-(BOOL) can1_maction :( SEL) action withSender :( id) sender
-(BOOL) can1_maction :( SEL) action withSender :( id) sender <br/>{< br/> BOOL retValue = NO; <br/> if (action ==@ selector (copy :)) <br/>{< br/> NSLog (@ "can1_maction"); <br/> retValue = YES; <br/>}< br/> else if (action = @ selector (paste :)) <br/>{< br/> NSLog (@ "canPerformAction "); <br/> retValue = NO; <br/>}< br/> else <br/>{< br/> retValue = [super can1_maction: action withSender: sender]; <br/>}</p> <p> return retValue; <br/>}
4. Execute the copy operation
// Perform the copy operation <br/>-(void) copy :( id) sender <br/>{< br/> UIPasteboard * gpBoard = [UIPasteboard generalPasteboard]; <br/> if (gpBoard) <br/>{< br/> NSString * copytext = @ "text"; <br/> [gpBoard setString: copytext]; <br/>}</p> <p>}
The above Code places the "text" string in the system clipboard.