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

前端 未结 4 1680
一向
一向 2020-12-13 18:03

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 th

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 18:43

    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!

提交回复
热议问题