Is there a way to set a default position for a UIPicker? I mean, if the user has the option of selecting any number from 1 to 100 in the UIPicker, can I set it to automatically start at 50?
A:
You can use selectRow:inComponent:animated: like this:
[somePickerView selectRow:49 inComponent:0 animated:NO]; // Zero-indexed, so row 49 is the row that says 50
You can fire it in the viewDidLoad method for the UIViewController managing the view which contains the UIPickerView.
(It could also be that you can specify the default value in Interface Builder, but I'm not sure and I didn't check...)
Douwe Maan
2010-06-16 18:15:30
When I add this, I don't get any type of error in the code - but the Picker is completely blank. When I comment out this line it goes back to normal - weird.
Rob
2010-06-17 02:32:39
Very weird indeed... You're sure the picker view is fully loaded before you're calling `selectRow:inComponent:animated`?
Douwe Maan
2010-06-17 10:17:36
AFTER it is fully loaded - it works now - thanks.
Rob
2010-06-17 16:29:40