gpt4 book ai didi

swift - NSButton 组作为单选按钮组

转载 作者:行者123 更新时间:2023-11-30 10:04:43 25 4
gpt4 key购买 nike

根据 Big Nerd Ranch 的书“Cocoaprogramming for OS X”,使用 NSMatrix 的旧方法将被弃用。新方法是使用多个 NSButton 实例,并将样式设置为 Radio。来自同一单选组的每个 NSButton 都应分配给一个共享的 @IBAction 方法。并在此操作方法中使用 tag 属性来区分它们。

Question is: How currently checked NSButton from radio group gets notification that another button was clicked, and current button should change its state to unchecked?

我知道问题:How to create NSRadioButton Group in Xcode 7 OSX但我的问题不是如何创建它。问题是消息如何到达其他 NSButton View ?因为 Action 是在 Window Controller 类上执行的,而不是在 View 上执行的。

图片如下:

        --> NSButton sends @IBAction ViewController.radioButtonPressed Window -|         --> NSButton sends @IBAction ViewController.radioButtonPressed

但是这两个实例如何在它们之间交换状态信息呢?看起来他们和ViewController之间的通信只有一种方式?一个按钮如何知道另一个按钮被按下?

最佳答案

该按钮位于 View 层次结构中,因此它可以请求其 super View 。然后它可以迭代 super View subview ,查找单选按钮类型的NSButton并比较action选择器以构建一个组。

关于swift - NSButton 组作为单选按钮组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36704194/

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