1

I want a UIPicker to popup instead of the keyboard when I click on a text field. Is this possible, I've been googling for awhile but can't find anything.

Does anyone have any sample code ?

Regards, Stephen

Stephen
  • 4,715
  • 8
  • 53
  • 78

2 Answers2

5

I think this is a more official way to do this:

UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
datePicker.tag = indexPath.row;
textField.inputView = datePicker;
Johan Kool
  • 15,637
  • 8
  • 64
  • 81
  • Very nice, worked well.. and if you would also like to easily add done button for dismissing picker. Check out this post.. http://stackoverflow.com/a/4827984/1154836 – josh527 Dec 13 '13 at 22:42
3

Use [self presentModalViewController:picker] to present a modal view controller when user click on the text field. I hoped that you know how to handle text field event

rene
  • 41,474
  • 78
  • 114
  • 152
vodkhang
  • 18,639
  • 11
  • 76
  • 110
  • Thanks for the help, I've gone back and looked over other questions I've posted, and thanked people for there help, where it was given. – Stephen Jul 09 '10 at 09:45
  • Not just thannks for people help. Their is a button under vote up/down that you can accept answer. – vodkhang Jul 09 '10 at 09:49
  • I get a popup box telling me that I need a reputation of 15 to vote up. – Stephen Jul 09 '10 at 09:54
  • Okay, sorry I see what your saying now. This button is not very clear, I'll back over my posts now. Sorry for any confusion. – Stephen Jul 09 '10 at 09:57
  • I'm having a little trouble with the following code: pvController = [[PickerViewController alloc] initWithNibName:@"PickerView" bundle:[NSBundle mainBundle]]; [window addSubview:pvController.view]; It's giving me errors stating that pvController is not declared. I don't see anywhere in the tutorial that declares this value. – Stephen Jul 09 '10 at 10:29
  • I've fixed this problem, please ignore the previous comment. – Stephen Jul 09 '10 at 11:24