我试图以编程方式创建UIPickerView并将其显示为文本字段的firstResponder,但是,选择器视图未显示. textField连接到接口构建器中的对象,但是正在以编程方式创建pickerView.
class View: UIViewController { @IBOutlet var picker : UIPickerView = UIPickerView.alloc() @IBOutlet var textField : UITextField = nil override func viewDidLoad() { super.viewDidLoad() picker = UIPickerView() picker.delegate = self picker.dataSource = self picker.backgroundColor = UIColor.blackColor() textField.inputView = picker } } extension View: UIPickerViewDataSource { func numberOfComponentsInPickerView(colorPicker: UIPickerView!) -> Int { return 1 } func pickerView(pickerView: UIPickerView!,numberOfRowsInComponent component: Int) -> Int { return 5 } } extension View: UIPickerViewDelegate { func pickerView(pickerView: UIPickerView!,titleForRow row: Int,forComponent component: Int) -> String! { return "Text" } }
为什么我在运行应用程序时看不到这个pickerView?