tags:

views:

209

answers:

1

I have a picker view that has a list of numbers to pick from. I want to be able to initialize the control at a particular row. For example, if the user specifies 10 as their default, then the control should be automatically positioned at that row when the control is first initialized.

Thanks in advance.

+1  A: 

You call selectRow:inComponent:animated: and pass it the index of the row you want selected.

This code causes a UIPickerView to spin through it's numbers 0 to 60 before coming to rest on zero.

- (void)viewDidAppear:(BOOL)animated{

    [thePicker selectRow:60 inComponent:0 animated:YES];
    [thePicker reloadComponent:0];
    [thePicker selectRow:60 inComponent:1 animated:YES];
    [thePicker reloadComponent:1];
    [thePicker selectRow:0 inComponent:0 animated:YES];
    [thePicker reloadComponent:0];
    [thePicker selectRow:0 inComponent:1 animated:YES];
    [thePicker reloadComponent:1];
}// End ------------------------------------viewDidAppear:------------------------------------

in your case to display row ten you would call something like:

[thePicker selectRow:10 inComponent:0 animated:YES];
TechZen
It's not working as expected. I put this code in viewDidLoad for the controller.Not sure why? [tipPicker selectRow:5 inComponent:0 animated:YES];
jp chance
The solution worked after I corrected IB issue.
jp chance
Nice demo. Thank you.
jp chance