From 4cef47a199e86f4e6bb2257c3ef32081ce7cfb47 Mon Sep 17 00:00:00 2001 From: Oskar Groth Date: Sat, 8 Apr 2017 14:13:16 +0200 Subject: [PATCH] Action correct status fix --- OGSwitch/OGSwitch.swift | 4 +++- OGSwitchDemo/AppDelegate.swift | 9 +++++++++ OGSwitchDemo/Base.lproj/MainMenu.xib | 8 ++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/OGSwitch/OGSwitch.swift b/OGSwitch/OGSwitch.swift index 9307199..d86db4b 100644 --- a/OGSwitch/OGSwitch.swift +++ b/OGSwitch/OGSwitch.swift @@ -257,12 +257,14 @@ public class OGSwitch : NSControl { } if isOn != on { + isOn = on if action != nil { NSApp.sendAction(action!, to: target, from: self) } + } else { + isOn = on } - isOn = on hasDragged = false isDraggingTowardsOn = false diff --git a/OGSwitchDemo/AppDelegate.swift b/OGSwitchDemo/AppDelegate.swift index cd715c3..cf63109 100644 --- a/OGSwitchDemo/AppDelegate.swift +++ b/OGSwitchDemo/AppDelegate.swift @@ -13,6 +13,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! + @IBOutlet weak var switchButton: OGSwitch! func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application @@ -22,6 +23,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } + @IBAction func switchPress(_ sender: Any) { + print("Trim is now: \(switchButton.isOn)") + perform(#selector(timer), with: nil, afterDelay: 3) + } + + @objc func timer() { + print("Trim is after now: \(switchButton.isOn)") + } } diff --git a/OGSwitchDemo/Base.lproj/MainMenu.xib b/OGSwitchDemo/Base.lproj/MainMenu.xib index 3c821bc..c42a57d 100644 --- a/OGSwitchDemo/Base.lproj/MainMenu.xib +++ b/OGSwitchDemo/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -15,6 +15,7 @@ + @@ -697,6 +698,9 @@ + + +