swift - NSButton RadioGroup (NSMatrix Alternative) -


i've tried few times set several similar buttons, connected same ibactions, , still can't seem replicate radiobutton behaviour.

at moment, have 5 buttons, children of 1 nsview..

nsview     - buttonone - nsbutton (square button)     - buttontwo - nsbutton (square button)     - buttonthree - nsbutton (square button)     - buttonfour - nsbutton (square button)     - buttonfive - nsbutton (square button) 

they're connected common ibaction, reads as:

@ibaction func activitybuttonpressed(sender: nsbutton) {      println("\(sender.title) pressed")  } 

which works point actual mosuedown events caught , sent func (as expected)..

how them working in radio button mode? i.e. have nsonstate , nsoffstate toggle when various buttons clicked?

when try , change button type radio button, automatically flips "switch"....

cheers,

a

since don't want use nsmatrix... first issue if using square button style, can't use radio type. want use on off type in interface builder.

here code used 4 buttons test out:

func buttonlist() -> array<nsbutton> {     return [button1, button2, button3, button4] }  @ibaction func buttonpressed(sender: nsbutton) {     abutton in buttonlist() {         if abutton == sender {             abutton.state = nsonstate         } else {             abutton.state = nsoffstate         }     } } 

as can see, iterates on of buttons, testing if button pressed. turns button on while turning other buttons off. need manage state want there, or checking state of of buttons:

func whichbutton() -> activitystate {    if button1.state == nsonstate { return activitystate.one }    if button2.state == nsonstate { return activitystate.two } ... 

where activitystate.one enum value can use determine state in.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -