IBOutlet on NSToolbarItem subclass causes image to disappear and interaction to be disabled
I am implementing a preferences window, with a subclass of NSToolbarItem
that has an IBOutlet
to an NSView
(the idea being that when an item is clicked, it will display its view). However, when I connect a toolbar item to an instance of the subclass, that item's image disappears and it is not clickable (although the text remains dark and does not fade).
If I disconnect the IBOutlet
, everything works again (well, nothing does, si开发者_Go百科nce it isn't bound to the view, but you get the idea).
Connecting the view to the NSToolbarItem
actually sets the view where the toolbar item's image normally is. This is useful in cases where you need a view in the toolbar (for example, the iTunes volume slider), but not in your case.
What you need to do is create an NSViewController
for your view, and create an IBAction
that shows the view. You should be able to connect the IBAction
to the toolbar item (in Interface Builder), and everything should work as expected.
精彩评论