How to replace a keyboard with a Uipickerview?

Asked

Viewed 103 times

3

I have a program, that an excerpt from the form, in case a UITextField, that needs to be filled in. But instead of a keyboard, I need a UIPickView, that already has the options for filling.

Then the moment the user starts the edition of this UITextField, I need that instead of the keyboard, a UIPickView.

The program is for iOS, using Objective-C.

  • 3

    I did not understand the vote outside the scope. I understand that the question is too broad, or until it is not clear enough. In scope it must be, because it appears to be a programming question.

  • I will edit to improve the explanation.

  • I made an issue on the question to improve understanding. I hope it’s become clearer now.

2 answers

4

Just add your own UIPickerView on the property inputView of UITextField. Supposing you have something like that when you start your View Controller:

_picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 270.0f)];
[_picker setDelegate:self];
[_picker setDataSource:self];

Add to your input:

[self.inputSelect setInputView:_picker];

So, go implementing the delegate appropriate to your case.

  • Thank you, I’ll test here and I’ll tell you if it worked!

  • Sorry I forgot the detail, it was for iOS 8

  • All right, but anyway my test was precisely on iOS 8, Xcode 6 GM.

  • The SOF could allow more than one alternative as an answer to the same problem, since it has things that can be done in 2 to 3 possible ways. :\

3


The problem is in iOS 8. To solve

pickerView = [[UIPickerView alloc] init];

[pickerView setDataSource: self];
[pickerView setDelegate: self];

[pickerView setFrame: CGRectMake(xPoint, 50.0f, pickerWidth, 200.0f)];

pickerView.showsSelectionIndicator = YES;

[pickerView selectRow:2 inComponent:0 animated:YES];

[self.view addSubview: pickerView];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0,xPoint , pickerWidth)]; // add autorelease if you don't use ARC

v.backgroundColor = [UIColor clearColor];
[v addSubview:pickerView];
editUFCRM.inputView = pickerView;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.