Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSButton state not changing

Tags:

swift

nsbutton

The following code works perfect in my sandbox:

@IBAction func filterClicked(sender: NSButton) {
  println(sender.state)
  if let clickEvent = NSApp.currentEvent! {
    if Int(clickEvent.modifierFlags.rawValue) & Int(NSEventModifierFlags.ControlKeyMask.rawValue) != 0 {
      if sender.state == NSOffState {
        sender.state == NSOnState
      }
    }
  }
  println(sender.state)
}

The connected button is an On-Off button. So when it's on and I ctrl-click it it will stay on.

Unfortunately in my app where I really need this it does not work. I checked that in both sandbox and prod app the bindings/settings are identically for both buttons. The debugger shows that

        sender.state == NSOnState

is simply not performed. state stays NSOffState. Gnawing my keyboard did not help. Any idea?

like image 770
qwerty_so Avatar asked Mar 17 '23 15:03

qwerty_so


1 Answers

You are not assign any value to the button state.

sender.state = NSOnState

Update for Swift 4.2

sender.state = NSControl.StateValue.on
like image 138
Superolo Avatar answered Apr 01 '23 22:04

Superolo