我已经在swift中创建了UIPickerView,并从名为Realm的本地存储中添加了数组值。在客户端告诉我在UIPickerView中设置默认选择行之前,一切都工作顺利且完美。
我担心的是,当从本地存储加载时,如何以编程方式在UIPickerView中设置默认选定行。这是我的代码的一部分。
private var pickerObjectView = UIPickerView()
override func viewDidLoad() {
let pickerObjectView = UIPickerView()
pickerObjectView.delegate = self
pickerObjectView.dataSource = self
pickerObjectView.showsSelectionIndicator = true
pickerObjectView.backgroundColor = UIColor.whiteColor()
}
func textFieldDidBeginEditing(textField: UITextField) {
if (textField.tag == 4) {
pickerArray = timeRange
/* Try to select 3 row in UIPickerView but not workint at all */
pickerObjectView.selectRow(3, inComponent: 0, animated: true)
}
}
请帮我怎么做?