var Months = ["A","B","C","D"]
var pickerview = UIPickerView()
@IBOutlet var txt_Month: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
pickerview.isHidden = true
pickerview.dataSource = self
pickerview.delegate = self
txt_Month.inputView = pickerview
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return Months.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
txt_Month.text = Months[row]
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return Months[row]
}
答案 0 :(得分:1)
也许是因为pickerview
被隐藏了吗?
答案 1 :(得分:0)
设置pickerview为未隐藏。
pickerview.isHidden = false