NSToolbarItem 子类上的 IBOutlet 导致图像消失并且交互被禁用
我正在实现一个首选项窗口,其中具有 NSToolbarItem
的子类,该子类具有到 NSView
的 IBOutlet
(其想法是,当单击某个项目时,它将显示其视图)。但是,当我将工具栏项连接到子类的实例时,该项目的图像消失并且不可单击(尽管文本保持黑色且不会褪色)。
如果我断开 IBOutlet 的连接,一切都会恢复正常(好吧,什么也不会发生,因为它没有绑定到视图,但你明白了)。
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, since it isn't bound to the view, but you get the idea).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将视图连接到 NSToolbarItem 实际上将视图设置为工具栏项图像通常所在的位置。这在您需要工具栏视图(例如 iTunes 音量滑块)的情况下很有用,但在您的情况下则不然。
您需要做的是为您的视图创建一个 NSViewController ,并创建一个显示该视图的 IBAction 。您应该能够将 IBAction 连接到工具栏项(在 Interface Builder 中),并且一切都应按预期工作。
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 anIBAction
that shows the view. You should be able to connect theIBAction
to the toolbar item (in Interface Builder), and everything should work as expected.