How to replace a keyboard with a UIPickerView?

3

I have a program, which a section of the form, in this case a UITextField , which needs to be filled. But instead of a keyboard popup, I need to get a UIPickView , which already has the options for the padding.

Then when the user starts editing this UITextField , I need a UIPickView to appear instead of the keyboard.

The program is for iOS, using Objective-C.

    
asked by anonymous 22.09.2014 / 16:31

2 answers

3

The problem is in iOS 8. To resolve

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;
    
22.09.2014 / 23:41
4

Just add your UIPickerView to the inputView property of UITextField . Assuming you have something like this when starting 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, you're implementing the appropriate delegate for your case.

    
22.09.2014 / 20:52