views:

166

answers:

1

Hello, I'm still rather new to iPhone development and I tried something I didn't it was possible. I have a UIView for my TableView Section Header with a switch on it, and I also have a UITableCellView with another Switch on it. It all looks fine, but now I want to propagate the UISwitch state from the section header to all the UISwitches on the section rows. Can anyone enlighten me how can I accomplish this?

Thank you.

A: 

Create a mutable array and whenever you create a table cell with a switch save a reference to the switch as a new element in the array. Then when the switch in your section header is changed, loop over the array and send a message to each switch, telling it to update its state.

UPDATE: for multiple sections, do the following

To keep track of which switch belongs to which header, set the tag property on the switches in the headers:

[myHeaderSwitch setTag:sectionHeader];

Then have an array of mutable arrays, one for each section as described above and use this to update the switches in the correct section

pheelicks
In that case I would need a Mutable Array for each section.
Reonarudo
Yes. That is correct
pheelicks
Thank you very much.
Reonarudo
There is one problem with your solution. When I flip the switch the switch doesn't know to which section header it belongs...
Reonarudo
See updated answer
pheelicks