iOS7 UISwitch its Event ValueChanged: Calling continuously is this Bug or what..?

Nitin Gohel picture Nitin Gohel · Oct 28, 2013 · Viewed 69.5k times · Source

Edit

It's now fixed on
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
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.

enter image description here

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:

enter image description here

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:

programmatic Add UISwitch

from XIB adding UISwitch

Answer

AeroStar picture AeroStar · Oct 28, 2013

Please see the following code:

-(void)viewDidLoad
{
    [super viewDidLoad];    
    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(130, 235, 0, 0)];    
    [mySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:mySwitch];
}

- (void)changeSwitch:(id)sender{
    if([sender isOn]){
        NSLog(@"Switch is ON");
    } else{
        NSLog(@"Switch is OFF");
    }
}