Edit
It's now fixed on ios7.1
Don't do any tweak to fix it.
Edit2
Apparently the same problem happens again in iOS 8.0 and 8.1
Edit3
It's now fixed on ios9.2
Don't do any tweak to fix it.
Hi Today i seen in UISwitch's
Event ValueChanged:
Calling continuously
while i am change to On
to Off
or Off
to On and my finger moved still on right side as well as left side. I atteched GIF image for more clear with NSLog.
My Value Changed Method is:
- (IBAction)changeSwitch:(id)sender{
if([sender isOn]){
NSLog(@"Switch is ON");
} else{
NSLog(@"Switch is OFF");
}
}
iOS6 the same code of Switch working Fine as we expectation:
so can anyone suggest me that call only one time its state On or off. or is this is a bug or what..?
UPDATE
Here it is my Demo of it:
Please see the following code:
I am still facing same problem in iOS 9.2
I got solution and posing as it might help others
Create count variable to trace number of times method got call
Save bool value for switch value
In Switch's value change method perform desire action for first method call only. When switch value again changes set count value andt bool variable value to default
If you don't need to react instantly to the switch's value change the following could be a solution:
If you are using so many switch in your app then there is problem to change the code in all places where t action method of UISwitch is defined.You can make custom switch and handle the events only if value change.
CustomSwitch.h
CustomSwitch.m
We are ignoring events if the value is same as changed value.Put CustomSwitch in all the class of UISwitch in storyboard.This will resolve the issue and call target only once when value changed
This issue is still here as of iOS 9.3 beta. If you don't mind the user not being able to drag outside of the switch, I find that using
.TouchUpInside
rather than.ValueChanged
works reliably.This works fine and doesn't calls the selector function again.