如何在iPhone的选择器选择行中显示文本字段值?

时间:2021-03-21 20:19:27

I have an application where I have a pickerview. In that picker I am displaying values from 1 to 100. When I select a value in picker say 2 that value is displayed in a textfield. I want that if my textfield contains value say 5 that value particular value should get displayed in my picker.

我有一个应用程序,我有一个pickerview。在该选择器中,我显示的值为1到100.当我在选择器中选择一个值时,表示该值显示在文本字段中。我希望如果我的文本字段包含值5,那么值特定值应该显示在我的选择器中。

Now problem is when in textfield 5 is displayed and I go to pickerview it shows by default every time 1 selected irrespective of the value in the texfield. I want the value which is present in the textfield should get displayed on the pickerview also.

现在的问题是当在textfield 5中显示并且我进入pickerview时它默认显示每次选择1而不管texfield中的值。我希望文本字段中存在的值也应该显示在pickerview上。

2 个解决方案

#1


2  

Use below code it will help you

使用下面的代码它会对你有所帮助

[picker selectRow:[yourTxtObj.text intValue]-1 inComponent:0 animated:YES];

#2


1  

[yourPickerViewName selectRow:[textfield.text intValue] inComponent:yourComponent animated:YES]

This will work. It is used for select a row in picker.

这会奏效。它用于在选择器中选择一行。

#1


2  

Use below code it will help you

使用下面的代码它会对你有所帮助

[picker selectRow:[yourTxtObj.text intValue]-1 inComponent:0 animated:YES];

#2


1  

[yourPickerViewName selectRow:[textfield.text intValue] inComponent:yourComponent animated:YES]

This will work. It is used for select a row in picker.

这会奏效。它用于在选择器中选择一行。