NSToolbarItem 子类上的 IBOutlet 导致图像消失并且交互被禁用

发布于 2024-11-18 06:04:21 字数 247 浏览 4 评论 0原文

我正在实现一个首选项窗口,其中具有 NSToolbarItem 的子类,该子类具有到 NSViewIBOutlet (其想法是,当单击某个项目时,它将显示其视图)。但是,当我将工具栏项连接到子类的实例时,该项目的图像消失并且不可单击(尽管文本保持黑色且不会褪色)。

如果我断开 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2024-11-25 06:04:21

将视图连接到 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文