选择器视图出现时最初如何选择值?
我在文本字段上设置了选择器视图外观开始编辑功能并隐藏键盘。现在的问题是,当选择器视图出现时,它会在第一个值上显示选择指示器,但该值不会显示在文本字段中。我希望当用户单击字段中的文本时,会出现选择器视图,并且选择器中的值将显示在选择指示器所在的文本字段中。怎么办呢?假设我有四个相同顺序的值0,1,2,3。现在,当选择器视图出现时,选择指示器的值为“0”。但要获得该值,我们必须滚动选择器视图并返回到“0”,然后它会在文本字段中显示该值。为什么会出现这种情况呢?以及如何自动获取价值?
预先感谢...
I have set a picker view appearance on text field begin editing function and hide keyboard. Now problem is that when picker view appear then it show selection indicator on first value but that value not show in text field. I want that when user click on text filed then picker view appear and value from picker will show in text field where selection indicator place. How do that? Suppose i have four value in same order 0,1,2,3. Now when picker view appear then selection indicator is at on '0' value. But to get that value we have to scroll picker view and come back to '0' then it show that value in text field. Why it is occurs? And how get value automatically?
Thanks in advances...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您的选择器视图和文本字段之间没有任何联系 - 您必须自己制作。
有两件事需要考虑:
1) 您的文本字段已经包含一个值,假设为“1”。当您打开选取器时,您可以使用函数
[yourPicker selectRow:1 inComponent:0animated:false]
将其设置为该值,假设选取器的数据数组为 [0, 1, 2, 3]。在您的情况下,要使文本字段包含值 0,只需调用
[textField setText:@"0"]
2) 当您完成选择器时,它会调用委托函数
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)行 inComponent:(NSInteger)组件
所以你必须让你的视图实现UIPickerViewDelegate协议,在其中实现上述委托函数并将视图设置为选择器视图的委托。
在委托函数中,您可以获取用户选择的值(使用行访问数据数组值)并在文本字段中设置该值。
Well, there is no connection between your picker view and the text field - you have to make it yourself.
There are two things to consider:
1) Your text field already contains a value, let's say "1". When you open the picker, you can set it to this value already with the function
[yourPicker selectRow:1 inComponent:0 animated:false]
, assuming your data array for the picker is [0, 1, 2, 3]. In your case, to make the text field contain the value 0, just call
[textField setText:@"0"]
2) When you are finished with the picker, it calls the delegate function
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
So you have to make your view implement the UIPickerViewDelegate protocol, implement the above delegate function in it and set the view as the picker view's delegate.
In the delegate function you can get the value the user picked (using row to access your data array values) and set this value in your textfield.