Search code examples
iosobjective-ccocoa-touchuiviewuimenucontroller

How do you create a UIMenuController for something that is not text-based?


Apple's Messages app, as well as many other third party apps support a UIMenuController style popover for selecting messages.

enter image description here

However, in browsing the documentation it seems that it's only used for text related selection.

Is it possible to extend it to other UIViews?


Solution

  • It's part of the tableView delegate API: http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:shouldShowMenuForRowAtIndexPath

    -(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; 
    

    Beyond that, the canPerformAction: responder API can be used to support actions, but you will be responsible for displaying the menu using UIMenuController.