Possible UISwitch error in iOS7?

I use UISwitch to call a routine to the screen in my application. However, the switch only works about 60% of the time. To check my code, I connected the switch to another IBAction to write the state of the switch to the console. Both functions do not respond to the state of the switch at certain points in time, that is, both functions simultaneously ignore the state of the switch. Has anyone else experienced this behavior using UISwitches in iOS7?

- (IBAction)showHideSomeSubView:(UISwitch *)sender { if (_mySwitch.on) { [self.view addSubview:someSubView]; } else { [someSubVew removeFromSuperview]; }} 

Edit:

The same switch is connected to the following action:

 - (IBAction)switchToggled:(UISwitch *)sender { sender = _mySwitch; if ([sender isOn]) { NSLog(@"On"); } else { NSLog(@"Off"); }} 

Both actions respond equally to the switch.

+7
ios ios7 uiswitch
source share
3 answers

I confirm that weird behavior with you !!!! Just drag the small circle of the switch around and around, you will see that the action is called several times (in my case up to 403: D) I'm really not sure what the Apple engineers intended to do this because I did not find any documentation about this new behavior. BTW, if you find it, let me know.

Many thanks

+4
source share

I use several UISwitches in an iOS 7 application, I had no problems responding to the Value Changed action. The switch sequentially reports its value correctly. You must unlock the switch from your action in IB and then reconnect, making sure that you connect the Value Changed action.

+3
source share

Yes, with UISwitch in the iOS 7 iPad simulator, I see 1-12 callbacks for my equivalent of your switchToggled: method. The last callback actually changed the value. In previous callbacks, this did not happen. What I am doing is caching whether the switch is on. Then, in the switchToggled: method, I check to see if the value has really changed. If it is not, I ignore the callback. This, apparently, leads to the correct operation of the user.

The problem also occurs on the device, although it seems to be less common. It seems that the same thing works there.

+3
source share

All Articles