I am using the UIMenuController on a custom UIView subclass. This means it can become first responder, and claims it canPerformAction on the “delete” action.
I would also like this view’s superview (also a custom UIView) to be able to use the menu controller, so on that superview, I have marked it as being able to be first responder, and implemented canPerformAction for different actions (“copy” and “cut” in this case).
Here’s the thing– when I make the menu visible from the (first) subview, it puts all three actions in the menu: delete, copy, and cut. In the debugger, I see canBecomeFirstResponder and canPerformAction being invoked on both views before the menu appears.
What’s going on here? Why isn’t the menu controller restricted to the view that’s become first responder? Or am I not diagnosing this correctly?
Thanks.
What code are you using?
In the documentation for canPerformAction:withSender:,
It seems to be contradictory, saying the default implementation recurses up the responder chain, but then also that UIMenuController recurses up the responder chain if you return NO.
The easiest fudge is probably to override
-nextResponderto return nil, but that might have other side-effects (for one, actions with a “nil” target go up the responder chain by default!).