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

前端 未结 4 1661
一向
一向 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:34

    @IBOutlet weak var mPicker: UIPickerView!
    var items: [String] = ["NoName1","NoName2","NoName3"] // Set through another ViewController
    var itemAtDefaultPosition: String?  //Set through another ViewController
    
    //..
    //..
    
    var defaultRowIndex = find(items,itemAtDefaultPosition!)
    if(defaultRowIndex == nil) { defaultRowIndex = 0 }
    mPicker.selectRow(defaultRowIndex!, inComponent: 0, animated: false)
    

提交回复
热议问题