Strange problem with NSMenuItem, user view and mouseUp:

I have a very strange problem with NSMenu.

About half of the NSMenuItems I use have custom views based on the setView method: NSMenuItem. In this user view, I implemented mouseUp: catch when the user clicks on a menu item, and this works great the first time the menu is opened.

The second time, however, mouseUp is not called in any of these menu items if I hold down the mouse button while clicking. However, if I click down, then move the cursor so slowly and release mouseUp. Therefore, for some reason, something intercepts these events, but only the second time a menu appears, and it passes if the cursor moves after the mouseDown event. (For some reason, mouseDown is never called, although the first or second menu appears).

Has anyone understood what is going on here? What is the interception of mouse events and why do they go through my user view when the menu first appears, but not the second?

+8
objective-c cocoa macos nsmenu nsmenuitem
source share
1 answer

I had the same problem. It turns out that the problem was that I started the external application after the first click of the menu, and when the menu was opened again, its window was no longer the key. Adding this method to a subclass of NSView. I use the corrected problem inside the menu items:

- (void)viewWillMoveToWindow:(NSWindow *)newWindow; { [super viewWillMoveToWindow:newWindow]; if ( newWindow != nil && ![newWindow isKeyWindow] ) [newWindow becomeKeyWindow]; [self updateTrackingAreas]; } 

For more information, check out this link: http://openradar.appspot.com/7128269

+3
source share

All Articles