How to set a default Value of a UIPickerView

前端 未结 7 1219
刺人心
刺人心 2020-12-13 05:42

I have a problem with my UIPickerView. I have 3 values in it EU AP and NA. When I start the app EU seems to be selected but when I make a NSLog(@\"%@\", [regions objec

7条回答
  •  半阙折子戏
    2020-12-13 06:11

    Swift solution:

    Define an Outlet:

    @IBOutlet weak var pickerView: UIPickerView!  // for example
    

    Then in your viewWillAppear or your viewDidLoad, for example, you can use the following:

    pickerView.selectRow(rowMin, inComponent: 0, animated: true)
    pickerView.selectRow(rowSec, inComponent: 1, animated: true)
    

    If you inspect the Swift 2.0 framework you'll see .selectRow defined as:

    func selectRow(row: Int, inComponent component: Int, animated: Bool) 
    

    option clicking .selectRow in Xcode displays the following:

    enter image description here

提交回复
热议问题