[英]How to implement UIPickerView for the textfield in for loop?
I am displaying text fields in a UIView
dynamically, based on JSON response data using a for
loop.我正在使用
for
循环基于 JSON 响应数据在UIView
动态显示文本字段。
I need to show a UIPickerView
for the each text field in the for loop, but it is only working for the last text field.我需要为 for 循环中的每个文本字段显示一个
UIPickerView
,但它仅适用于最后一个文本字段。 I am unable to display a UIPickerView
for each of the text fields.我无法为每个文本字段显示
UIPickerView
。 Can anyone please help me to solve this issue?任何人都可以帮我解决这个问题吗?
So you are inside your for loop with an i index.所以你在你的 for 循环中,有一个 i 索引。 What we are looking here is to assign a UIPickerView as each textfield's input view .
我们在这里寻找的是分配一个 UIPickerView 作为每个文本字段的输入视图。 Try something like this...
尝试这样的事情......
//FOR LOOP BEGINS
//Iteration - Create a textfield.
[self.view addSubview:yourTextfield];
//Assign a uipickerview as textfield's input view.
UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.frame = CGRectMake(0,0,300,300);
pickerView.tag = i;
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
textField.inputView = pickerView;
[self.view addSubview:pickerView];
//Iteration ends
//FOR LOOP ENDS
PS You can also add a toolbar with each pickerView to your textfield using the inputAccessoryView PS 您还可以使用 inputAccessoryView 将带有每个 pickerView 的工具栏添加到您的文本字段
You can set the number of rows to a large number, and make it start at a high value, there's little chance that the user will ever scroll the wheel for a very long time -- And even then, the worse that will happen is that they'll hit the bottom.您可以将行数设置为一个很大的数字,并使其从一个高值开始,用户滚动滚轮很长时间的可能性很小 - 即便如此,更糟糕的情况是他们会触底。 you can see this: How do you make an UIPickerView component wrap around?
你可以看到: 你如何让 UIPickerView 组件环绕?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.