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:
- You add a custom menu in the usual fashion.
- In the canPerformAction you filter which action you want to enable/show
- 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);
}
精彩评论