gpt4 book ai didi

swift - Xcode 单选按钮在单击后不会切换到关闭状态

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

我有 2 个单选按钮和一个用于计算一些代码的按钮。要点是只允许选择 1 个单选按钮,以便计算按钮完成其工作,但由于某种原因,当我构建项目并选择其中一个单选按钮时,我无法再取消单击它。有谁知道为什么会这样吗?

最佳答案

如果您遵循 Interface Builder 为单选按钮显示的提示,它就会起作用:

For a single choice among mutually-exclusive options.

For apps running on 10.8 and later, creating radio groups with individual NSButton objects (rather than an NSMatrix) is preferred.

Radio buttons automatically act as a group (selecting one button will unselect all other related buttons) when they have the same superview and -action method.

仅仅将它们全部放在同一个 super View 中是不够的(刚刚测试并确认了这一点),您还需要将它们连接到相同的操作。

将它们全部放在同一个 super View 中:

Radio Buttons in Stack View

将它们分别连接到相同的操作:

Radio Button Action

@IBAction func clickedRadioButton(_ sender: NSButton)
{
print("Clicked \(sender.title)")
}

然后,每次您选择其中一个单选按钮时,其他单选按钮将自动取消选择,并且将使用您选择的按钮调用您的操作方法。

关于swift - Xcode 单选按钮在单击后不会切换到关闭状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43075388/

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