Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group radio buttons (from storyboard) in cocoa application?

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)enter image description here

in cocoa application I didn't find any elegant way to do so...

any suggesting before I do something ugly?

like image 792
Aviram Netanel Avatar asked May 16 '16 08:05

Aviram Netanel


People also ask

How do you add radio buttons to groups?

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.

How do I group radio buttons in eclipse?

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.

What property used to set the radio buttons to a group?

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.

How do I group radio buttons in VB net?

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.


1 Answers

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.

like image 171
Ron Reuter Avatar answered Oct 04 '22 22:10

Ron Reuter