Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Garrett Cox
Garrett Cox
4,797 Points

UISwitch to make text field appear

I am hoping to have a switch, that once the state is changed, a text field will appear for the user to input text.

This will be for an app that can lookup their location, but if they move the switch, they could then enter in an address instead.

There seem to people minimal resources on the UIswitch that involve something like that.

2 Answers

Kieran Robinson
Kieran Robinson
9,411 Points

Hiya mate, https://drive.google.com/file/d/0B4qNq90-3k9CX0xaano0eWRrenc/edit?usp=sharing thats a link to a project i made to show you a very simple example of this. Hope it helps, Kieran

The UISwitch has a delegate method called "valueChanged" you could possibly use that. Based on whatever the value is, in that method, show or hide the textfield.