I'm trying to group 2 radio buttons in cocoa application.
but unlike in iOS, where you can connect the buttons with control-drag (as shown in the picture)
in cocoa application I didn't find any elegant way to do so...
any suggesting before I do something ugly?
You group radio buttons by drawing them inside a container such as a Panel control, a GroupBox control, or a form. All radio buttons that are added directly to a form become one group. To add separate groups, you must place them inside panels or group boxes.
Select all the buttons you want to group by pressing CTRL and the button. Right click on one of the buttons and select properties. In the ButtonGroup of the Properties, click on the down arrow. Your selection of button groups should appear.
Use the GroupName property to specify a grouping of radio buttons to create a mutually exclusive set of controls. You can use the GroupName property when only one selection is possible from a list of available options. When this property is set, only one RadioButton in the specified group can be selected at a time.
The RadioButton control is used to provide a set of mutually exclusive options. The user can select one radio button in a group. If you need to place more than one group of radio buttons in the same form, you should place them in different container controls like a GroupBox control.
NSMatrix used to be the solution, but it is now discouraged:
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.
If all buttons call the same action method and are in the same supperview, Cocoa automatically selects the clicked button and deselects the previous button and -- no code necessary to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With