我想将一个按钮文本设置为UIPicker所选标题。
我有以下代码:
@IBOutlet weak var picker: UIPickerView!
@IBOutlet weak var dureeBtn: UIButton!
@IBAction func changerDuree(sender: AnyObject) {
picker.hidden = !picker.hidden
}
let _names = ["1", "2", "3", "4", "5", "6"]
let _vals = [1, 2, 3, 4, 5, 6]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return _names.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return _names[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
dureeBtn.titleLabel!.text = _names[row]
}
它有时会起作用(大约50%),但在其他时候会切换到默认值。 以下是截图:
以前有人有这个问题吗? 谢谢!