Jeesson_7
Jeesson_7

Reputation: 811

UISwitch is not working when we slide over it in IOS 10.2

I have been getting this error that when i slide over my switch its state "On" and "Off" is not working in iOS 10.2 running phones. However when i click on it, The same switch gets it states called correctly. I crosschecked it with a iOS 9.3 running phone. Here both state work correctly both when sliding finger or on click. Is it a minor bug of iOS 10.2 or is it the problem with my code(I don think so, as it work correctly in 9.3)

My code

  @IBAction func Switch_clicked(sender: AnyObject)
{
    if switch_btn.on
    {

        print("button on")
        self.EnableTouchID()

    }


    else
    {

        print("button off")
        self.DisableTouchID()


    }

}

Note: The main problem is that switch gets slideded on to "ON" or "OFF" without invoking .on or .off states

Upvotes: 1

Views: 1005

Answers (1)

PGDev
PGDev

Reputation: 24341

Try this:

Check the event type of UISwitch for which the IBAction method is called. It must be valueChanged.

enter image description here

@IBAction func onChangeSwitchState(_ sender: UISwitch)
{
    if sender.isOn
    {
        print("button on")

    }
    else
    {
        print("button off")
    }
}

Upvotes: 1

Related Questions