gpt4 book ai didi

objective-c - 设置 NSToolbarItem 未选中

转载 作者:行者123 更新时间:2023-12-03 16:30:44 24 4
gpt4 key购买 nike

我目前正在尝试定义一个带有可选 NSToolbarItemsNSToolbar,它代表绘图 OSX 应用程序中的工具。我希望用户能够通过单击来选择和取消选择要使用的工具(NSToolbarItems)

如果您碰巧了解 Sketch,这就是我正在寻找的工具栏行为:

Selected Tool Screenshot

在上图中,您可以看到选中的“编辑”工具。如果再次单击该项目,它将被取消选择:

Unselected Tool Screenshot

我一直在阅读有关工具栏的 Apple 文档,但没有找到有关如何实现能够选择/取消选择工具栏项目的效果的信息。在“可选择的工具栏项目”中,它显示:

Your application can specify the currently selected toolbar item using the method setSelectedItemIdentifier: passing the identifier for the desired toolbar item. The currently selected toolbar item is returned by the method selectedItemIdentifier. If there is no currently selected, nil is returned.

但我还没有找到 setSelectedItemIdentifier: 方法的定义位置,或者它是否可以解决我的需求。

现在我的工具栏项目发生的情况是,一旦单击,只能通过单击另一个可选择的项目来取消选择它们。一旦点击某个项目,总会有一个选定的项目。

有什么简单的方法可以解决这个问题吗?我是否遗漏了文档中解释如何实现此效果的重要部分?

非常感谢!

答案:所以最终就像将 NSToolbarselectedItemIdentifier 设置为 nil 一样简单。这会导致所选元素被取消选择。

最佳答案

为了取消选择 NSToolbarItem ,就像设置 selectedItemIdentifier 一样简单NSToolbar的反对 nil .

我最初对苹果文档感到困惑,在 Selectable Toolbar Items部分,因为它指出:

[...] The currently selected toolbar item is returned by the method selectedItemIdentifier. If there is no currently selected, nil is returned.

所以我想selectedItemIdentifier只是一个返回当前选定的工具栏项目的方法(没有设置,只是获取)。但我相信这应该是一个错字。 selectedItemIdentifier是 get/set 属性,事实上,将其设置为 nil 会取消选择所有项目。

关于objective-c - 设置 NSToolbarItem 未选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37281133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com