3

I have a UITextField which I have set it's inputView to be of a UIPickerView so the user can choose between a few values there. However I'm having trouble making the textfield become first responder.

If I set my textfield userInteractionEnabled = NO then it won't become first responder but if I set it to YES it will become first responder but then I will have a blinking cursor in there which I do not want. So how to make a read-only UITextField become first responder?

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • Why not use a UILabel and have the picker be the first responder? – rdelmar Oct 08 '12 at 21:37
  • You can't assign `inputView` to a `UILabel` – Peter Warbo Oct 08 '12 at 21:54
  • 3
    Sure, and there's no need to. Bring up a picker, by whatever means works in your app, and the populate the UILabel from the pickerView:didSelectRow:inComponent: delegate method. It might be the only way to go, if it's not possible to make a read-only text field the first responder. – rdelmar Oct 08 '12 at 21:58

1 Answers1

0

From your question it looks you dont need a UITextField. So an alternative way to achieve this is to have a UILabel with a UIButton added on top, which will bring the picker. On selection of any value in picker, the UILabel text can be modified.

iDev
  • 23,310
  • 7
  • 60
  • 85