问题描述
我想以编程方式启用和禁用macOS中NSToolBar的工具栏项目(按钮).我试图为ViewController控件拖动创建一个出口,但是Xcode不接受该放置.我该怎么办?
I would like to enable and disable programmatically a toolbar item (a button) of a NSToolBar in macOS. I tried to create an outlet to ViewController control-dragging but Xcode don't accept the drop. How can I do this?
我阅读了此问题关于带有Objective-C答案的类似问题,但我我是个初学者,不太了解如何在Swift中执行此操作.
I read this question about a similar question with Objective-C answers but I'm a beginner and can't understand well how to do this in Swift.
推荐答案
实现委托方法
override func validateToolbarItem(_ item: NSToolbarItem) -> Bool
例如,您可以通过itemIdentifier
区分项目,并返回true
启用和false
禁用该项目
You can distinguish the items for example by the itemIdentifier
and return true
to enable and false
to disable the item
文档提供了一个示例.
这篇关于如何在Swift中禁用macOS X的NSToolbar的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!