I have an NSCollectionView with an NSView bundle in it vertically folded so that it looks a bit like a UIKit UITableView . Everything works as expected, except for one:
When right-clicking on any of NSView s, I expect NSMenu be displayed, which will display menu , but alas, nothing happens.
The crazy part is that all the correct methods are called exactly as you would expect: -rightMouseDown: -menuForEvent: and, finally, -menu .
When I set an object as the NSMenu delegate , menuWillOpen: is not called, so it seems to me that something is failing on the Apple side for the menu and actually showing it.
Can anyone shed some light on this?
Thanks in advance.
PS. For what it's worth, NSMenu , I show it manually (without using Apple's right-click processing) using popUpMenuPositioningItem:atLocation:inView:
Change / Update / Clarify
NSCollectionView is inside an NSWindow that displays when you click NSStatusItem , for example CoverSutra / TicToc / what you have. Some code from the MyWindow NSWindow subclass:
- (void)awakeFromNib { [self setStyleMask:NSBorderlessWindowMask]; [self setExcludedFromWindowsMenu:YES]; } - (BOOL)canBecomeMainWindow { return YES; } - (BOOL)canBecomeKeyWindow { return YES; } - (BOOL)isMovable { return NO; } - (void)presentFromPoint:(NSPoint)point { point.y -= self.frame.size.height; point.x -= self.frame.size.width / 2; [self setFrameOrigin:point]; [self makeMainWindow]; [self makeKeyAndOrderFront:self]; }
presentFromPoint: is the method that I use to present it from anywhere that I like, in my case just below NSStatusItem . (Not very important for this problem)
My application has LSUIElement in its Info.plist installed on YES , by the way, therefore it does not display a menu bar or dock icon. It is located in the status bar and has a window that appears when you click NSStatusItem .
The hierarchy of views is as follows:
MyWindow => contentView => NSScrollView => NSCollectionView
NSCollectionView has a subclass of NSCollectionViewItem connected to the itemPrototype property, and a subclass of NSCollectionViewItem has a subclass of NSView connected to the view property. The NSView subclass, in turn, has an NSMenu associated with its menu property. And last, but not least, this NSMenu has one NSMenuItem sitting inside it.
Both the NSCollectionViewItem subclass and the NSView subclass NSView nothing interesting at the moment, they are just empty subclasses.
NSMenu associated with the NSView menu property is what should be displayed when the NSView right- NSView , but I hope I have made it clear: this is not really shown.
Update
I still don’t know what caused this problem, but I decided to “move” with NSCollectionView , since it was not very suitable for what I was trying to do anyway, and now I use TDListView , which works like a charm.