我正在尝试在 Cocoa 应用程序中对 2 个单选按钮进行分组。
在 Cocoa 应用程序中,我没有找到任何优雅的方法...
在我做丑陋的事情之前有什么建议吗?
最佳答案
NSMatrix 曾经是解决方案,但现在不鼓励使用:
NOTE: Use of NSMatrix is discouraged in apps that run in OS X v10.8 and later. If you need to create a radio button group in an app that runs in OS X v10.8 and later, create instances of NSButton that each specify a button type of NSRadioButton and specify the same action and the same superview for each button in the group.
如果所有按钮都调用相同的操作方法 并且 在相同的 super View 中,Cocoa 会自动选择单击按钮并取消选择上一个按钮,并且不需要代码来执行此操作。
关于objective-c - 如何在 cocoa 应用程序中对单选按钮(来自 Storyboard)进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37249986/