IOS UIMenuController UIMenuItem, how to determine item selected with generic selector method

前端 未结 4 864

With the following setup

....
MyUIMenuItem *someAction  = [[MyUIMenuItem alloc]initWithTitle : @\"Something\"  action : @selector(menuItemSelected:)];
MyUIMe         


        
4条回答
  •  不知归路
    2020-12-10 07:25

    One would expect that the action associated with a given menu item would include a sender parameter that should point to the chosen menu item. Then you could simply examine the title of the item, or do as kforkarim suggests and subclass UIMenuItem to include a proeprty that you can use to identify the item. Unfortunately, according to this SO question, the sender parameter is always nil. That question is over a year old, so things may have changed -- take a look at what you get in that parameter.

    Alternately, it looks like you'll need to a different action for each menu item. Of course, you could set it up so that all your actions call a common method, and if they all do something very similar that might make sense.

提交回复
热议问题