iosobjective-ciphoneuitableviewpasteboard

Simple way to show the 'Copy' popup on UITableViewCells like the address book App


Is there a simple way for subclasses of UITableViewCell to show the 'Copy' UIMenuController popup like in the Address book app (see screenshot), after the selection is held for a while?

address book
(source: icog.net)


Solution

  • The method before iOS 5 is to get the UIMenuController's shared instance, set the target rect and view and call -setMenuVisible:animated:. Remeber to implement -canPerformAction:withSender: in your responder.


    The method after iOS 5 (previously available as undocumented feature) is to implement these 3 methods in your data source (see https://developer.apple.com/reference/uikit/uitableviewdelegate#1653389).

    -(void)tableView:(UITableView*)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender;
    -(BOOL)tableView:(UITableView*)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender;
    -(BOOL)tableView:(UITableView*)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath*)indexPath;