Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set UIPickerView at other than the default index?

I have an integer having value of 5 and I want to start my UIPickerView with this index, now what should I do? normally UIPickerView is on default 0 index row, but I want it on index which is user defined, as can be 5, 6 or any other digit.

like image 350
Chatar Veer Suthar Avatar asked Feb 15 '11 13:02

Chatar Veer Suthar


2 Answers

Assuming your picker is referred to in a property "myPicker", then in viewDidLoad, go:

[self.myPicker selectRow:rowInt inComponent:componentInt animated:NO]
like image 90
Dan Ray Avatar answered Sep 21 '22 17:09

Dan Ray


Update for Swift 4.2:

To set the default row in a UIPickerView,

  myPicker.selectRow(5, inComponent: 0, animated: true)

where myPicker is the name of the UIPickerView and 5 is the index of the desired row.

like image 21
Marcy Avatar answered Sep 19 '22 17:09

Marcy