UIPickerView
您好,当用户单击文本字段时,我正在尝试以编程方式弹出视图。我已经尝试过了,但它没有做任何事情,它不起作用。单击文本字段时没有任何反应
class UserProfileTableViewController: UITableViewController,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource {
var itemPicker: UIPickerView! = UIPickerView()
@IBOutlet weak var genderTxtField: UITextField!
var gender = ["MALE","FEMALE"]
override func viewDidLoad() {
super.viewDidLoad()
genderTxtField.delegate = self
itemPicker!.delegate = self
itemPicker!.dataSource = self
itemPicker!.backgroundColor = UIColor.blackColor()
self.genderTxtField.inputView = itemPicker
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{
return 1
}
// returns the # of rows in each component..
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
return gender.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return gender[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
genderTxtField.text = gender[row]
//.hidden = true;
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
itemPicker.hidden = false
return false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}