I'm going to assume you're dynamically creating the switches, not creating them in IB. If that's the case, you'll need to do two things to receive and distinguish changes to your switches. First, when you create the switch, set its tag
property to some value that represents the corresponding section (like maybe the section index itself). Then, add an event handler to the switch that will call back to a method on your view controller.
So, in tableView:viewForHeaderInSection:
, lazily instantiate your header view, maybe caching it, then say something like:
[switch setTag:section];
And add the event handler thusly, where switchToggled: is defined just as any other IBAction would be:
[switch addTarget:self
action:@selector(switchToggled:)
forControlEvents:UIControlEventValueChanged];
Then, just cast the sender
you receive in your event handler to UISwitch *
, and use the tag
property to tell which switch was toggled.