简体   繁体   中英

UISwitch propagate state

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM