简体   繁体   English

如何在for循环中为文本字段实现UIPickerView?

[英]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.

相关问题 如何多次使用UIPickerView和TextField? - How to use UIPickerView with TextField more than once? 具有多个TextField的动态UIPickerView - Dynamic UIPickerView with multiple TextField 如何在警报内将UIPickerView用作文本字段 - How can I do an UIPickerView as Textfield inside an Alert 将UIPickerView与TextField的inputView关联时,如何重置? - How do I reset a UIPickerView when it is associated with a TextField's inputView? 当选择了另一个文本字段时,如何重置UIPickerView内部的值? - How to reset the values inside the UIPickerView when the other textfield is selected? 如果代理数据在文本字段上为空,如何使UIPickerView不显示? - How to make UIPickerView not to display if delegate data is empty on textfield touch? 如何在不使用 UIPickerView 的情况下在 tvOS 中实现下拉列表? - How to implement a dropDown list in tvOS without using UIPickerView? 如何通过iOS应用程序中的UIPickerView实现视图之间的转换? - How to implement transitions between views via a UIPickerView in iOS application? 如何在单个页面中实现多个UIPickerView? - How can I implement multiple UIPickerView in a single page? 如何在文本框中实现“用键盘移动视图”功能 - How to implement “move view with keyboard” function into textfield
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM