Search code examples
iosmenuuimenucontroller

iOS: How to get the selected UIMenuItem from UIMenuController


I am trying to use UIMenuCnotroller to show a list of dynamically generated items, they share the same action method, and so I need to know which item is selected in the single action method.

However, in the action method - (void)menuItemAction:(id)sender;the sender is actually the UIMenuController object, and I didn't find any method of UIMenuController can tell me which menuitem is selected.

One solution I can think of is to dynamically generate different action selectors for different items, and do some tricks in forwardInvocation

But is there any easier way?


Solution

  • Okay, I've solved this one. It involves messing with [NSObject forwardInvocation:] and is a bit dirty, but the resulting code is quite minimal. Answered over here: https://stackoverflow.com/a/9874092/790036