I want to show an NSPopover
from an NSToolbarItem
button in my toolbar.
(i.e. positioned below the button).
Ideally, I want to pass the NSView
of the button to the popover to position it.
My question is, how do I get the NSView
of the NSToolbarItem
?
[toolbarbutton view]
always returns nil.
The answer appears to be in the video for the 2011 WWDC Session 113, "Full Screen and Aqua Changes." Basically, put an NSButton inside the NSToolbaritem and use the view of that.
A blog post is here: http://www.yellowfield.co.uk/blog/?p=33, and a sample project is on github at http://github.com/tevendale/ToolbarPopover
All in the sprit of http://xkcd.com/979!
You can send the action directly from the NSButton
enclosed in the NSToolbarItem
(which is what you should generally do anyways, consider segmented controls, where each segment has its own target/action), and that will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With