I'm trying to get the following code work:
UIMenuController * menu = [UIMenuController sharedMenuController];
[menu setTargetRect: CGRectMake(100, 100, 100, 100) inView: self.view];
[menu setMenuVisible: YES animated: YES];
The menu instance is ready but it doesn't show - the width is always zero.
Or is there some sample code on this UIPasteboard/UIMenuController
topic?
If you're implementing a custom view and that view is supposed to be the responder (as opposed to some other view, like a UITextField), you need to override the canBecomeFirstResponder function in your view and return YES:
then, when you're displaying the menu, you should do something like the following:
I think Cam is right, need override both canPerformAction and canBecomeFirstResponder
to display UIMenuController one has to add following
UIMenuController doesn't have a view. I just searched some code from apple's iPhone Application Programming Guide: Event Handling:
Don't you have to add the
UIMenuController* menu
to the main or subview, E.G.self.view
? I think it's something like[self.view addSubView:menu.view];
Or am I missing the point of your question. You might also want to set the frame of the menu's view.In case somebody still has problems: My menu used to work and some day stopped working miraculously. Everything else in my app still worked. Now I had removed the
[window makeKeyAndVisible]
method fromapplication:didFinishLaunchingWithOptions:
method, and while everything else still worked, this breaksUIMenuController
!Stupid error on my side, difficult to find the culprit...