开发者

How to grab parent sender for UIMenuController

Context: I have added my custom menu item to the UIMenuController. Everything works just fine, the canPerformAction is called as expected when the custom item is tapped.

Here is my problem: within the view where the menu is displayed I have a few textview. I want to be able to grab the current selected text from the current textview when the custom menu is tapped.

I can’t because the sender is not the object that is hosting/showing the menu开发者_运维百科 but the menucontroller itself.

How do I find the sender/UI_control (parent?) where the menu has been shown?


The way is supposed to work is:

  1. You add a custom menu in the usual fashion.
  2. In the canPerformAction you filter which action you want to enable/show
  3. When the action occurs you check the current responder and there you apply your logic.

The canPerformAction withSender never returns you the current control that is visually hosting the custom menu.

You can find out who is the first responder looping all the views and check the isFirstResponder property. Or if you have just a couple if you can do a quick check for those two.

    // called by canPerformAction
    if ([myTextBox isFirstResponder]) {
    NSLog(@"Found it!", nil);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜