karl karl - 4 months ago 36
Swift Question

Swift: How to set a default Value of a UIPickerView with three components in Swift?

How do I set the starting row of the picker view in Swift?
I see there is a code for Objective C, but I don't understand it. If anyone could explain how I can translate the Objective C code into Swift that would also be fantastic !

Thanks

Answer

This is the code I have used in one of my Apps:

// Declare the outlet to the picker in your storyboard
@IBOutlet var MyPicker: UIPickerView!

//...


override func viewDidLoad() {
//...
MyPicker.selectRow(row, inComponent: 0, animated: true)
}

Obviously, replace row and 0 with whatever values you want.

Hope this Helps!