iphone SDK: How to set the initial value of a UIPickerView?

Viewed 25666

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.

4 Answers

Try this it's working for me , just one line of code .

In Objective-C

   [self.picker selectRow:2 inComponent:0 animated:YES];

In Swift

  picker.selectRow(2, inComponent:0, animated:true)

Hope this will help some one .

Related