Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting a change in UISwitch

Tags:

This sounds trivial but I'm noticing some weirdness. I've wired up a handler for the Value Changed event of a UISwitch. What I would expect is that each time the handler is called the value of the switch would change. But that's actually not always the case. If you press the switch rapidly on/off the handler can get called consecutively with the SAME state for the switch (in my specific application this is an issue). So I'm wondering if anyone else has noticed this behavior and has figured out a good solution.

like image 302
John Avatar asked Nov 04 '10 16:11

John


1 Answers

   -(void) createSwitch     {         self.searchExistSearchNewSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0,0,0,0)];         [self.searchExistSearchNewSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];         [self.view addSubview:self.searchExistSearchNewSwitch];     }     - (void)switchValueChanged:(UISwitch *)theSwitch     {         BOOL flag = theSwitch.isOn;     } 
like image 140
user1105951 Avatar answered Oct 07 '22 03:10

user1105951