我用UIPickerView
爲標籤選擇數據:點擊UIPickerView
class BookingOptionsViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var lblProfile: UILabel!
var data = ["1", "2", "3"]
var picker = UIPickerView()
override func viewDidLoad() {
super.viewDidLoad()
picker.delegate = self
picker.dataSource = self
let tap = UITapGestureRecognizer(target: self, action: #selector(tap(gestureReconizer:)))
lblProfile.addGestureRecognizer(tap)
lblProfile.isUserInteractionEnabled = true
}
func tap(gestureReconizer: UITapGestureRecognizer) {
print("*")
picker.isHidden = false
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return data.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
lblProfile.text = data[row]
self.view.endEditing(true)
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return data[row]
}
}
當我點擊標籤,我想表明我UIPickerView
,但picker.isHidden = false
不起作用。 我該怎麼做才能顯示UIPickerView
?
@Krill你在哪裏隱藏你的選取器我的意思是picker.hidden = false是在那裏,但是picker.hidden = true在哪裏? –