Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I am working on implementing something in my iOS app that I see in mobile websites all the time. I would like to have a TextBox or TextField of some kind that shows what value is currently selected. When clicked, it will present a UIPickerView with a list of possible choices. Upon selection, the UIPickerView will disappear, and the TextBox or TextField would get updated with the selection the user made. Can someone point me in a good direction for doing this?
 
A UITextField has a property inputView which by default is the iOS keyboard. What this means is whenever the text field becomes the first responder, it presents this view. You can change this view to anything you want, but then it becomes your responsibility to update the text field.

So what you need to do is create your picker with your options (data source). Set your picker as your textfield's inputView:
Code:
[myTextField setInputView:myPickerView]
In your picker's delegate method (didSelectRow:inComponent:), you need to set the selected row of the picker as your text field's text.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.