I have a switch in my screen, and when the user wants that option to be on, I need to collect some more information from that user. So I need to present two text fields. And if the user does not want to use that feature, then they select the off switch, and I do not need to collect the contact information, and I would like to hide the text fields which collect the information.
Here is my sceen:

Where do I need to put the “listener” and the code to hide/show the extra text fields and labels when the user toggles a switch?
Thanks!
The
UIViewControllercontaining the switch is the logical place to handle events coming from the switch. From the image I see you already have the switch wired up. You can declare an IBAction method and wire the switch’s valueChanged event to it:In the implementation of that method you can hide/show the labels and text fields. The quick-and-dirty approach would be to have those extra labels and fields always present on the view, but hidden. You can toggle the
hiddenproperty in response to the user toggling a switch.You could also wrap those extra labels and fields inside a view which you dynamically add to or remove from the main view in response to a switch being toggled.