我需要你的帮助。我正在使用 textField 打开一个pickerView(并且我成功地做到了)。但我真正需要做的是在pickerview(或任何地方)上放置一个文本字段并将其设为SearchTextField。可能吗?
到目前为止,这是我的代码:
class pruebaPickerViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{
@IBOutlet weak var textField: TextField!
var list = ["iPhone 6s", "iPhone 6s Plus", "iPhone SE"]
override func viewDidLoad() {
super.viewDidLoad()
var pickerView = UIPickerView()
pickerView.delegate = self
pickerView.dataSource = self
textField.inputView = pickerView
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int{
return list.count
}
func pickerView(_ pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -> String! {
return list[row]
}
func pickerView(_ pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
textField.text = list[row]
}
}