如何在Swift中禁用macOS X的NSToolbar的按钮? [英] How to disable a button of a NSToolbar of macOS X in Swift?

查看:160
本文介绍了如何在Swift中禁用macOS X的NSToolbar的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式启用和禁用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的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆