I have a UITableView with a variable amount of cells, each with a UISwitch. Here is the line for all the switches:
[cell.currentSwitch addTarget:self action:@selector(changeCurrentEvent:) forControlEvents:UIControlEventValueChanged];
I have it set up that when you flip one switch, it turns off all of the others (inside of -changeCurrentEvent:). What I’m noticing, is that -changeCurrentEvent: is called properly when I manually flip a switch, but since it turns all the others off, therefore changing their value, shouldn’t they each call -changeCurrentEvent: as well? That’s what I want them to do anyway.
Control events are only sent if the control is changed by user action (e.g. tapping, in the case of a switch). If you’re changing values in code, they aren’t sent.
This nicely avoids infinite loop situations where controls are updated in response to other controls changing, which cause other controls to change…
Your implementation of
-changeCurrentEvent:should make all the necessary changes to your model in response to the single switch being changed.