UIPickerView To Select and Display Option

Discussion in 'iOS Programming' started by newtoiphonesdk, May 4, 2012.

  1. newtoiphonesdk macrumors 6502a

    Jul 30, 2010
    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?
  2. CodeBreaker macrumors 6502

    Nov 5, 2010
    Sea of Tranquility
    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:
    [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.
  3. nathanlloyd macrumors member

    Dec 7, 2009
  4. forum user macrumors regular

    Aug 28, 2008
    Thanks! Should work now

Share This Page